examples: annotate examples
[nit.git] / lib / pthreads / README.md
1 # POSIX Threads support
2
3 The threads can be manipulated and synchronized using the classes `Thread`,
4 `Mutex` and `Barrier`.
5
6 This group also provides two optional modules with thread-safe collections:
7
8 * `redef_collections` redefines existing collection to make them thread-safe.
9   This incures a small overhead in all usage of the redefined collections.
10 * `concurrent_collections` intro new thread-safe collections.
11
12 Theses services are implemented using the POSIX threads.
13
14 You can also use the `is threaded` annotation on methods, which makes them run on their own thread.
15 Methods with self calls are not supported.
16
17 A method or function annotated with `is threaded` has its return value changed during compilation.
18 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`.
19 A call to the `join` method will block the execution until the threaded method is done, or immediatly return if it's already done.
20 `join` will return an object typed with the orginial return type, or `null` if there wasn't.
21
22 ## Known limitations:
23
24 * Most services from the Nit library are not thread-safe. You must manage
25   your own mutex to avoid conflicts on shared data.
26 * FFI's global references are not thread-safe.
27
28 ## For more information:
29
30 * See: `man pthreads`
31 * See: `examples/concurrent_array_and_barrier.nit`
32 * See: ̀ examples/threaded_example.nit`