Question: For this problem, assume sequential consistency (memory operations happenin program order). Recall the critical section problem: a solution must provide mutual exclusion, progress, and bounded

 For this problem, assume sequential consistency (memory operations happenin program order).

For this problem, assume sequential consistency (memory operations happenin program order). Recall the critical section problem: a solution must provide mutual exclusion, progress, and bounded waiting. Mutexes are a solution to this problem. An alternative solution is Peterson's algorithm. (We alluded to this solution but did not cover it.) Below is Peterson's solution, adapted to a lock-ike API, and assuming two threads. It is correct (assuming sequential consistency): it provides mutual exclusion, progress, and bounded waiting. Set all fields to zero on initialization int wants(2];wants 1 means tread i wants or has lock int not_turn:r not this thread's tum if other one wants lock " is thread number, which must be 0 or 1 void peterson_lock (struct peterson "p, int i) p-not tum while (p-wants(14 && p.)not tur-i) F i is thread number, which must be 0 or 1 " void peterson_unlock (struct peterson p, int p->wants0 Using a global "struct peterson globallock, two threads can synchronize with while (1) ( peterson lock (&globallock, i). Critical section for thread0 peterson unlock (8globallock, i Other stuff_for_thread i0 But is not turn actually required? Consider an alternative implementation of peterson lock) Mis thread number, which must be 0 or 1 "y void peterson lock at (struct peterson "p, int i) while (p->wants 1-) Is peterson_lock_alt an acceptable replacement for peterson_ lock? If so, justify. If not, give a problematic interleaving, and state why it is problematic. Remember that we are assuming sequential consistency

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!