Presentation is loading. Please wait.

Presentation is loading. Please wait.

Hardware solutions So far we have looked at software solutions for the critical section problem. –algorithms whose correctness does not rely on any other.

Similar presentations


Presentation on theme: "Hardware solutions So far we have looked at software solutions for the critical section problem. –algorithms whose correctness does not rely on any other."— Presentation transcript:

1 Hardware solutions So far we have looked at software solutions for the critical section problem. –algorithms whose correctness does not rely on any other assumptions (OS or hardware) Hardware solutions are easier and more efficient. They rely on special machine instructions –TSL –swap Very similar in use – must be supported by the hardware

2 Test and Set Lock (TSL) Entering and leaving a critical region

3 Test-and-Set in BACI atomic int testset (int& i)// i is LOCK { if (i = = 0) {//if ok to enter critical section… i = 1;//set LOCK to 1 to keep others out return 1;//set testset to 1 to let this process in } else // i = = 1, so can’t get in return 0; } When i = = 0, requesting process will get into its critical section. The instruction is executed atomically, i.e. as one uninterruptable unit. If two test-and-set instructions are executed simultaneously they will be executed sequentially in some arbitrary order.

4 How to call testset Use in the following context... –Declare a boolean variable bolt, initialized to false... repeat while (!testset(bolt)); //busy wait until testset is 1 critical section bolt := 0; //let another process in until false;

5 The swap instruction Pseudocode for swap: void swap (int& lk, int& k) { int temp; temp = a; a = b; b = temp; } How to call it (deliberately vague – more details on lab sheet): –A global variable lock is declared and initialized. –Each process has a local variable key. It assigns key a value before calling swap. –The call swap(lock,key) is made in a loop until it gains entry to its critical section –When a process leaves its critical section, it resets lock so another process can get in.

6 How effective are these hardware solutions? These algorithms meet the mutual exclusion requirement, but not necessarily the bounded waiting requirement. Why? The calls can be rewritten in the software to achieve bounded waiting.


Download ppt "Hardware solutions So far we have looked at software solutions for the critical section problem. –algorithms whose correctness does not rely on any other."

Similar presentations


Ads by Google