1
votes

I am sharing some memory (created with shm_open where I map different "regions" with mmap) across multiple processes. I am using named semaphores to synchronize accesses to that memory.

I have a region in that memory that is read-only (it has been set by the process that creates the shared memory object). Do I still need to use mutexes to let the processes read that region? If that region can be read concurrently I can drop named semaphores and share unnamed semaphores instead.

The question is similar to what asked here but maybe the OP was not clear enough.

1
As long as the shared memory is set before any read only access and never changed after that intialization, you can safely to concurrent reads. - Serge Ballesta

1 Answers

1
votes

According to multiple sources, reading the same memory seems to not introduce race conditions, so it could be done without locking. I have a couple of systems running from months with one process writing (with a global lock) and two other processes continuosly reading the same shared memory and I have never had issues.