Pthreads tasks run concurrently, so they need a mechanism to coordinate access to resources (while that is not necessary for cooperative multitasking).
Mutexes can only be locked by one thread at one time, all other threads have to wait until the mutex is unlocked.
create a named mutex name, initially unlocked.
name execution: ( – mutex )
If mutex is currently locked, wait until it is unlocked. Lock mutex.
Unlock mutex.
You can ensure that you always unlock a mutex after locking it by using:
If mutex is currently locked, wait until it is unlocked. Lock mutex, then execute xt. After xt finishes (regularly, or through an exception), unlock mutex.