All the documentation I\'ve read on the pthreads mutex states only that a mutex prevents multiple threads from accessing shared memory, but how do you specify in the program
a mutex prevents multiple threads from accessing shared memory
The above is an incorrect statement. By itself, a mutex does not do that. It lets you build code that prevents multiple threads from accessing shared memory or other resources concurrently, but it does not lock anything by itself.
You can build a program that uses a mutex to prevent multiple threads from executing specific pieces of code concurrently. If these pieces of code happen to be accessing a shared memory region, and no other code would try accessing that region concurrently without locking the mutex, then the effect would be that of "locking" that region of memory.