thrd_join synchronizes a calling thread with the termination of a specified thread. The terminating thread’s thrd_exit or return synchronizes with the corresponding thrd_join. section 21.2
Joining worker threads
After main creates several threads, it joins them in a known order. Once main joins the last thread, including the account thread, all effects those threads made on data objects are visible to main. section 21.2
TAKEAWAY:
- Joining establishes visibility of the terminated thread’s effects; detaching instead removes this thrd_join synchronization point. section 21.2
Table 21.1 C library functions that form synchronization pairs
| Release | Acquire |
thrd_create(.., f, x) |
Entry to f(x) |
thrd_exit by thread id or return from f |
Start of tss_t destructors for id |
End of tss_t destructors for id |
thrd_join(id) or atexit/at_quick_exit handlers |
call_once(&obj, g), first call |
call_once(&obj, h), all subsequent calls |
| Mutex release | Mutex acquisition |
Use the synchronization-pairs table to compare thrd_join with thrd_create, thrd_exit, call_once, and mutex operations. section 21.2
