Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is POSIX's equivalent of Win32's Mutex?

Tags:

c

pthreads

POSIX's mutex is equivalent to Win32's CRITICAL_SECTION -- its scope is limited to a single process. Win32's mutex (Actually called a "mutant" in NT land) serves as a cross process locking mechanism. What is pthreads' equivalent for cross-process locks?

like image 202
Billy ONeal Avatar asked Jan 23 '11 10:01

Billy ONeal


1 Answers

It's a pthread_mutex_t with a pshared attribute set to PTHREAD_PROCESS_SHARED . However, you're responsible to place such a mutex in shared memory, that all processes can access - so it's not as simple as the win32 api.

Perhaps closer to win32 is a posix or sysv semaphore. Traditionally, synchronization across processes has also been done using file locks e.g. flock or lockf (this is in no way as slow as it might sound)

like image 92
nos Avatar answered Sep 20 '22 03:09

nos