The only way to make mutexes interprocess is to enable pthread_mutexattr_setpshared attribute. This hasn't been done in the article's code so the mutex which is used there hase an inter-thread scope, not an inter-process scope.
I am sorry but that is not true. I have compiled some test code with gcc 3.3.6 and started two instances of it and the output showed that the mutex did not block between processes, at least not with the options from the article (both processes are in the critical section at the same time). Where did you get the information that pthread mutexes synchronise between processes? Man pages for pthread_mutex_init, pthread_mutex_lock, pthread_mutex_trylock etc do not mention it at all.
The code shown is using pthread mutex for sync-ing. The mutex works only for synchronization of threads, not processes so the code is useless (even dangerous) for inter process communication (IPC). In the case of threads another question is just screaming for an answer:
Why would someone use a shared memory block for threads which are all running in the same memory space anyway?
We come to the conclusion that the code is quite useless for inter-thread communication too. All in all - useless.
I know, my bad :) should read more carefully
The only way to make mutexes interprocess is to enable pthread_mutexattr_setpshared attribute. This hasn't been done in the article's code so the mutex which is used there hase an inter-thread scope, not an inter-process scope.
I am sorry but that is not true. I have compiled some test code with gcc 3.3.6 and started two instances of it and the output showed that the mutex did not block between processes, at least not with the options from the article (both processes are in the critical section at the same time). Where did you get the information that pthread mutexes synchronise between processes? Man pages for pthread_mutex_init, pthread_mutex_lock, pthread_mutex_trylock etc do not mention it at all.
The code shown is using pthread mutex for sync-ing. The mutex works only for synchronization of threads, not processes so the code is useless (even dangerous) for inter process communication (IPC). In the case of threads another question is just screaming for an answer:
Why would someone use a shared memory block for threads which are all running in the same memory space anyway?
We come to the conclusion that the code is quite useless for inter-thread communication too. All in all - useless.