# Linux Kernel Module Cheat

##### 27.4.4.1. pthread_mutex

userland/posix/pthread_count.c exemplifies the functions:

- `pthread_mutex_lock`

- pthread_mutex_unlock

That example that the same interface as: atomic.cpp. There are no non-locking atomic types or atomic primitives in POSIX: http://stackoverflow.com/questions/1130018/unix-portable-atomic-operations

`pthread_mutex_lock` and `pthread_mutex_unlock` and many other pthread functions already enforce cross thread memory synchronization:

- https://stackoverflow.com/questions/78172/using-c-pthreads-do-shared-variables-need-to-be-volatile/58935671#58935671

- https://stackoverflow.com/questions/3208060/does-guarding-a-variable-with-a-pthread-mutex-guarantee-its-also-not-cached

- https://stackoverflow.com/questions/24137964/does-pthread-mutex-lock-contains-memory-fence-instruction