Question: Starting with the test-and-test_and_set lock of Figure 13.8, implement busy-wait code that will allow readers to access a data structure concurrently. Writers will still need

Starting with the test-and-test_and_set lock of Figure 13.8, implement busy-wait code that will allow readers to access a data structure concurrently. Writers will still need to lock out both readers and other writers. You may use any reasonable atomic instruction(s) (e.g., LL/SC). Consider the issue of fairness. In particular, if there are always readers interested in accessing the data structure, your algorithm should ensure that writers are not locked out forever.

Figure 13.8:

type lock = Boolean := false; procedure acquire lock(ref L: lock) while not test and set(L) while L -- nothing -- spin procedure release lock(ref L: lock) L:= false

type lock = Boolean := false; procedure acquire lock(ref L: lock) while not test and set(L) while L -- nothing -- spin procedure release lock(ref L: lock) L:= false

Step by Step Solution

3.27 Rating (162 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

ANSWER type lock Boolean false type readerslock Integer 0 procedure acquirelockref L lock while ... View full answer

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 Programming Language Pragmatics Questions!