C POSIX Multithreading Programming


$ man 7 pthreads

Pthreads man page

Multithreading Programming Guide (Oracle)

pthread.h

System Interfaces: Threads


Synchronization (Wikipedia)


Shared resources and mutexes


Resources shared by several threads should be protected by mutexes.

Since these shared resources are bottlenecks mutex should be locked the least possible time.


Mutex and race conditions


To avoid race conditions, mutexes should lock in the same order.

A mutex that is locked and always unlocked next cannot cause race conditions (one level lock).