Confusing question regarding semaphores and threads

I am not able to understand this dependency diagram because there are no arrows in it! Whether thread A should execute first, release thread B and either B releases C or both A and B are required to release C. Kindly guide!

Here is the question: https://ibb.co/v4vK8JC
I'd say the first place to start is here https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-createsemaphorea

A semaphore is like a mutex but allows access to a certain number of threads at a time. Usually 2 or more. If it was only one at a time you'd just use a mutex.

That being said, based on the problem you have 3 threads I'd assume that they all share a variable, or object (like a file) which you need to protect with a semaphore so that 2 only have access at a time. One doesn't release the other. They'd basically take turns. If threads started a,b,c in order. A and b would access it first, when a is done b & c would access. B done a and c and so on.

To make the thread wait for the object use https://docs.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-waitforsingleobject
Topic archived. No new replies allowed.