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 doesn't lock memory, it "locks" a part of the execution path, and synchronizes memory (but when locking and when unlocking). What is guaranteed is that if one thread holds the mutex, no other threads can acquire it, and any thread attempting to acquire it will be blocked until it is released.
It is also guaranteed that any memory accesses (read or write) will be ordered with respect to acquiring or releasing the mutex; in other words, that any reads made while the mutex is held will reflect any changes made before the mutex was acquired (including those made in a different thread), and that any modifications made while the mutex is held will be potentially visible to all other threads at the latest when the mutex is released. (The other threads will, of course, have to ensure that their memory reads see up to date values for this to work.)
For more information, you really should read Programming with POSIX Threads, by David Butenhof. It's the reference, and explains them in detail.