Protect Shared State with pthread_mutex_lock
A POSIX mutex does not make a variable magically private; it gives cooperating threads one serialized critical section and establishes synchronization around protected state. Build a checked C example, understand why the unlocked version is undefined, find races with ThreadSanitizer, and choose between mutexes and atomics.