SHM_LOCK
is not a mutual-exclusion tool. It is just a request to the kernel that the pages in the shared memory segment not be swapped out of memory - similar to mlock()
.
If you want mutual exclusion using the SYSV IPC APIs (shmctl()
is one of these), then you need to use SYSV semaphores (semctl()
/ semget()
/ semop()
).