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.
man pthreads
examples/concurrent_array_and_barrier.nit
pthreads :: concurrent_collections
Introduces thread-safe concurrent collectionsactors > examples > agent_simulation
a "Framework" to make Multi-Agent Simulations in Nitnitc > interpreter > dynamic_loading_ffi
This group implement a partial support for the Nit FFI in the interpreter.actors > examples > fannkuchredux
Example implemented from "The computer Language Benchmarks Game" - Fannkuch-Reduxactors > examples > mandelbrot
Example implemented from "The computer Language Benchmarks Game" - Mandelbrot