pthreads -
POSIX Threads support
The threads can be manipulated and synchronized using the classes Thread
,
Mutex
and Barrier
.
This group also provides two optional modules with thread-safe collections:
redef_collections
redefines existing collection to make them thread-safe. This incures a small overhead in all usage of the redefined collections.concurrent_collections
intro new thread-safe collections.
Theses services are implemented using the POSIX threads.
You can also use the is threaded
annotation on methods, which makes them run on their own thread.
Methods with self calls are not supported.
A method or function annotated with is threaded
has its return value changed during compilation.
You will get a subclass of Thread
, even if there wasn't a return value before. You can know if the threaded method is done with the is_done
boolean from Thread
.
A call to the join
method will block the execution until the threaded method is done, or immediatly return if it's already done.
join
will return an object typed with the orginial return type, or null
if there wasn't.
Known limitations:
- Most services from the Nit library are not thread-safe. You must manage your own mutex to avoid conflicts on shared data.
- FFI's global references are not thread-safe.
For more information:
- See:
man pthreads
- See:
examples/concurrent_array_and_barrier.nit
- See: ̀ examples/threaded_example.nit`
Content
- pthreads: POSIX Threads support (lib/pthreads)
- concurrent_collections: Introduces thread-safe concurrent collections (lib/pthreads/concurrent_collections.nit)
- examples (lib/pthreads/examples)
- concurrent_array_and_barrier: A basic usage example of the modules
pthreads
andpthreads::cocurrent_collections
(lib/pthreads/examples/concurrent_array_and_barrier.nit) - jointask_example: Simple example of joinable task using threadpool (lib/pthreads/examples/jointask_example.nit)
- threaded_example: test for threaded annotation (lib/pthreads/examples/threaded_example.nit)
- threadpool_example: Simple example using threadpool (lib/pthreads/examples/threadpool_example.nit)
- concurrent_array_and_barrier: A basic usage example of the modules
- extra: Offers some POSIX threads services that are not available on all platforms (lib/pthreads/extra.nit)
- pthreads: Main POSIX threads support and intro the classes
Thread
,Mutex
andBarrier
(lib/pthreads/pthreads.nit) - redef_collections: Redef some basic collections to be thread-safe (lib/pthreads/redef_collections.nit)
- threadpool: Introduces a minimal ThreadPool implementation using Tasks (lib/pthreads/threadpool.nit)