Question: 2 threads can work consequtively by using busy waiting; as we can see below. what if there are 3 threads, how can we write it?
2 threads can work consequtively by using busy waiting; as we can see below. what if there are 3 threads, how can we write it?
While (TRUE) {
flag1 = 1;
turn = 0;
while ((turn ==0) && (flag2 == 1));
critical_region();
flag1 = 0;
noncritical_region();
}
While (TRUE) {
flag2 = 1;
turn = 1;
while ((turn ==1) && (flag1 == 1));
critical_region();
flag 2 = 0;
noncritical_region();
}
How can you solve this problem for more than two processes?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
