Title: Critical Section Review Problems
1Critical Section Review Problems
2Problem 1
- Thread 1
- x x1
- /
- ld r1,x
- add r1,1
- st r1,x
- /
- Thread 2
- x x1
- /
- ld r1,x
- add r1,1
- st r1,x
- /
Question Give an execution sequence where the
two threads execute concurrently and the final
value of X is one. Assume that initial value of X
is zero.
3Problem 2
- Thread 1
- Enter_Mutex
- while (busy 1)
- busy 1
- Exit_Mutex
- busy 0
Thread 2 Enter_Mutex while (busy 1)
busy 1 Exit_Mutex busy 0
Question Give an execution sequence where both
the threads execute concurrently, and the first
thread sets busy 1 and still the second thread
goes past the while loop. busy is initialized
zero.
4Problem 3
- Thread 1
- Enter_Mutexwhile (turn 2)
- Exit_Mutex
- turn 2
Thread 2 Enter_Mutexwhile (turn
1) Exit_Mutex turn 1
Question Which two requirements of critical
section solution are violated? Give a scenario
for violations.
5Problem 4
Question Which of the four requirements for the
critical section solution are violated?
6Problem 5
Question Which of the four requirements for the
critical section solution are violated?
7Problem 6
- TSL R, Lock TSL Test and Set LockR
register, Lock memory location - Atomically (atomic nothing can interfere) -
Read Lock into R - Store a non-zero value into
Lock
Question What should be the code to enter the
critical section? Code to exit the critical
section?