I've got a queue resource that is shared across multiple producers and multiple consumers. All are independent processes; no one process "owns" the queue.
By nature of the implementation access to the queue must be controlled and only one process must be allowed to push or pop at any given moment.
I figured using a POSIX named semaphore would be the right solution, however a few of the details are bothering me. (This is a Linux-only implementation, btw.)
When (if ever) should I do a sem_unlink? Is there any reason to actually remove the queue?
I'm concerned about a process dying while holding the queue semaphore locked. Is there any good way around this? I can do a timed wait when trying to get the lock, but if the timeout expires I've now got a race condition.
Is there a better solution for a simple binary lock like this? Perhaps a lockfile using fcntl and/or exclusive opens?
Thanks.