I have two semaphores x (initially at 1) , and y (initially at 0).
My thread function code is somewhat like this:
...
wait(x);
//setting some vars
signal(x);
wait(y);
...
I want to ensure that the threads wait on y in line, ie. if the first thread completed the x-guarded section first, it should get to wait on y first, & so on. In the current implementation, a context switch occuring after signal(x); can prevent this from happening.
Is there a way to do this, or do I have to restructure the code completely to prevent this eventuality?