I have implemented two applications that share data using the POSIX shared memory API (i.e. shm_open). One process updates data stored in the shared memory segment and another process reads it. I want to synchronize the access to the shared memory region using some sort of mutex or semaphore. What is the most efficient way of do this? Some mechanisms I am considering are
- A POSIX mutex stored in the shared memory segment (Setting the PTHREAD_PROCESS_SHARED attribute would be required)
- Creating a System V semaphore using
semget
boost::interprocess.tmpfsorhugetlbfs? I'd probably use a POSIX mutex since they've been very fast for several years on Linux.mmap()a file on atmpfsorhugetlbfs?