Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed
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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts Of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

4th Edition

0619064625, 978-0619064624

More Books

Students also viewed these Databases questions

Question

Different formulas for mathematical core areas.

Answered: 1 week ago