Question: This is for an Operating Systems class: int flag [21i int turn; void init) flag [O] = turn 0 flag [1] = 0; // 1->

This is for an Operating Systems class:

This is for an Operating Systems class: int flag [21i int turn;

int flag [21i int turn; void init) flag [O] = turn 0 flag [1] = 0; // 1-> thread wants to grab lock // whose turn? (thread 0 or 1?) void lock ( flag [self] = 1; turn = 1 - self; while ((flag[l-self1) && (turn1 self)) // self: thread ID of caller // make it other thread's turn ; spin-wait void unlock ) f flag Iself 0; // simply undo your intent 3. The inset alongside depicts code for the software only lock solution by Peterson and Dekker for enforcing critical sections. Assume that Thread 0 is created with variable self-0, and Thread 1 with set-1. a. Thread 0 runs first, calls lock), but is switched out after executing line flag[selfl-1. After this point which thread will enter the critical section first? Trace the steps. (3 points) b. If thread 0 is switched out after executing the second line in lock turn-1-self) which (3 points) thread will enter the critical section first? Once again, trace the steps

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!