Instances of this class are each used to launch and control a thread.
# Handle to a thread # # Instances of this class are each used to launch and control a thread. 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: E do return null private fun main_intern: E do # Register thread local data sys.self_thread_key.set self var r = main self.is_done = true return r end # Start executing this thread # # Will launch `main` on a different thread. fun start do if native != null then return native = new NativePthread.create(self) end # Join this thread to the calling thread # # Blocks until the method `main` returns or the target thread calls # `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: E do if native == null then start var r = native.join native = null return r.as(E) end redef fun finalize do if native == null then return native.free native = null end endlib/pthreads/pthreads.nit:300,1--357,3