pthreads adding a virtual type for synchronization purposes
authorBlackMinou <romain.chanoir@viacesi.fr>
Tue, 7 Apr 2015 09:25:54 +0000 (11:25 +0200)
committerBlackMinou <romain.chanoir@viacesi.fr>
Tue, 14 Apr 2015 06:30:49 +0000 (08:30 +0200)
Signed-off-by: BlackMinou <romain.chanoir@viacesi.fr>

lib/pthreads/pthreads.nit

index 8b8de1f..afb66d6 100644 (file)
@@ -236,19 +236,26 @@ end
 abstract class Thread
        super Finalizable
 
+       # Type returned by `main`
+       type E : nullable Object
+
        private var native: nullable NativePthread = null
 
+       # Is this thread finished ? True when main returned
+       var is_done = false
+
        # Main method of this thread
        #
        # The returned valued is passed to the caller of `join`.
-       fun main: nullable Object do return null
+       fun main: E do return null
 
-       private fun main_intern: nullable Object
+       private fun main_intern: E
        do
                # Register thread local data
                sys.self_thread_key.set self
-
-               return main
+               var r = main
+               self.is_done = true
+               return r
        end
 
        # Start executing this thread
@@ -266,12 +273,12 @@ abstract class Thread
        # `Sys::thread_exit`. Returns the object returned from the other thread.
        #
        # Stats the thread if now already done by a call to `start`.
-       fun join: nullable Object
+       fun join: E
        do
                if native == null then start
                var r = native.join
                native = null
-               return r
+               return r.as(E)
        end
 
        redef fun finalize