Release a protected critical section
A thread protects the shared game state while creating cells, then releases the mutex so another thread can enter: mtx_lock(&L->mtx); life_birth9(L); mtx_unlock(&L->mtx); Here, mtx_unlock releases the mutex acquired by the calling thread; the protected operation is the critical section. section 20.4
mtx_unlock is the C threads-library operation that ends exclusive access to a mutex. Its release synchronizes with a later successful acquisition of the same mutex, making effects from earlier protected critical sections visible. section 20.4 section 21.2
Keep these rules in view:
- Pair mtx_unlock with a mutex acquisition around the shared data that requires mutual exclusion. section 20.4
- Treat release as part of the synchronization protocol: critical sections protected by the same mutex occur sequentially. section 21.2
- Use the mutex consistently when coordinating threads that modify or observe the same protected object. section 21.2
int mtx_lock(mtx_t*); int mtx_unlock(mtx_t*); int mtx_trylock(mtx_t*); int mtx_timedlock(mtx_t*restrict, const struct timespec*restrict);
The related mutex interface places mtx_unlock beside mtx_lock, mtx_trylock, and mtx_timedlock, clarifying its role as the release operation. section 20.4
