Does semaphore Mach work in shared memory between processes?

I am interested in using a semaphore created using semaphore_create(task, sem, policy, value) from mach/semaphore.h in shared memory to synchronize two processes on Mac OS.

I know that on Linux using sem_init(sem, pshared, value) , pshared should be non-zero in this case, however I cannot find information on Mac (where sem_init not implemented), and I really don't want to use the named semaphores since I will need to create a lot of them.

I experimented with a minimal example and it doesn't seem to work, so I wonder if I did something wrong or just doesn't work. I am also open to other alternatives between processes.

+4
source share
2 answers

Here's the documentation for semaphore_create and friends: https://developer.apple.com/library/mac/#documentation/Darwin/Conceptual/KernelProgramming/synchronization/synchronization.html

I donโ€™t have a Mac, so I canโ€™t verify anything, but I donโ€™t see the reasons why unnamed semaphores are impossible.

0
source

OSX does not support anonymous semaphores. Function calls are implemented to get posix matching, but if you check return codes, they actually fail with an unsuccessful error. I wrote a post with more details about OSX and unnamed semaphores here, as well as a suggested solution: Unnamed-semaphores-and-pososx

0
source

All Articles