Question: This section of code is something that I wrote to provide mutual exclusion between two threads. ( Sorry about the formatting - it's Canvas. )
This section of code is something that I wrote to provide mutual exclusion between two
threads. Sorry about the formatting it's Canvas. Comments?
bool blocked;
void thread int id
int other :;
while true
while blocked other ; wait in while loop
blocked id true;
critical section here, then...
blocked id false;
other code here...
As long as blockedid is initialized to false for both it is fine.
Of course it works, this is really the code for a spinloop or like a testandset.
It does not work. Between falling out of the inside while loop and entering the section, the other
thread could also enter.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
