Original Post
Ok, this is technically related to my university work, so up front I'll say this: I don't want the answer, just general hints regarding the approach that I could find in a text book. Thanks. I have 3 processes that periodically require access to 2 resources, represented by 2 more processes. I need to mediate access between them so that the 3 producer processes do not suffer starvation/deadlock/etc and can be allocated one of the 2 consumer resources (doesn't matter which) as soon as one becomes available. I can't add another process and I can't use any synchronisation primitive except for a binary semaphore. This seems like a producer/consumer problem, but is complicated by having a choice of coupling between each producer and consumer. My initial thought was that I need a semaphore that signifies "at least one of the two consumers is free", but that's not enough because if both are free I need the other to be getting accessed as well. So as soon as I release that semaphore there's a chance someone else will snap up the resource that was just indicated as free. How about using one semaphore as above, which provides mutually exclusive access to 2 boolean globals signifying the availability of the 2 resources, then another semaphore for each of those 2 resources, one of which will get acquired, before the original semaphore is released and the resource is used. Then that resource process will acquire that main semaphore again, set itself to being available, release its own semaphore, and release the main one. Does that sound reasonable? I have a feeling there's a chance of deadlock in there...