Question
Consider the following coroutines (two threads executing concurrently on a single CPU). Because CPU can only execute one instruction at a time, the instructions from
Consider the following coroutines (two threads executing concurrently on a single CPU). Because CPU can only execute one instruction at a time, the instructions from the two threads are interleaved with each other (in some arbitrary order).
boolean[] flag = {false, false};
P0: P1:
while (flag[1]) while (flag[0])
busy-waiting; busy-waiting;
flag[0] = true; flag[1] = true;
enter critical-section; enter critical-section;
do critical-section work; do critical-section work;
exit critical-section; exit critical-section;
flag[0] = false; flag[1] = false;
All questions in this part pertain to above coroutines and are T / F; mark your answers clearly!
- If process P1 dies before entering the critical section, then process P0 may get prevented from entering the critical section indefinitely.
TRUE FALSE
- If P0 enters critical section and then gets terminated while still inside of critical section, then process P1 will definitely be prevented from entering the critical section.
TRUE FALSE
- The Boolean array flag[] and the overall implementation of P0 and P1 guarantees mutual exclusion, i.e., these two coroutines cannot both be inside the critical section at the same time.
TRUE FALSE
- It is not possible that, during some execution sequence of P0 and P1, both values flag[i] = true at the same time (for i = 0, 1).
TRUE FALSE
- If P0 and P1 execute at approximately the same speed and the OS context-switches between the two threads with fairness, then it will be guaranteed that P0 and P1 wont be inside the critical section at the same time.
TRUE FALSE
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started