Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 22 Syed Mansoor Sarwar

Similar presentations


Presentation on theme: "Lecture 22 Syed Mansoor Sarwar"— Presentation transcript:

1 Lecture 22 Syed Mansoor Sarwar
Operating Systems Lecture 22 Syed Mansoor Sarwar

2 © Copyright Virtual University of Pakistan
Agenda for Today Review of previous lecture Semaphores based solutions for the critical section problem Deadlock and starvation Binary and counting semaphores Recap of lecture 7 December 2018 © Copyright Virtual University of Pakistan

3 © Copyright Virtual University of Pakistan
Review of Lecture 21 The Bakery algorithm Hardware based solutions 7 December 2018 © Copyright Virtual University of Pakistan

4 © Copyright Virtual University of Pakistan
A Good Solution ‘key’ local; ‘lock’ and ‘waiting’ global All variables set to false do { waiting[i] = true; key = true; while (waiting[i] && key) key = TestAndSet(lock); waiting[i] = false; 7 December 2018 Critical Section © Copyright Virtual University of Pakistan

5 © Copyright Virtual University of Pakistan
A Good Solution j = (i+1) % n; while ( (j != i) && !waiting[j] ) j = (j+1) % n; if (j == i) lock = false; else waiting[j] = false; Remainder Section } 7 December 2018 © Copyright Virtual University of Pakistan

6 © Copyright Virtual University of Pakistan
Solution with Test-And-Set Is the given solution good? Yes Mutual Exclusion: Satisfied Progress: Satisfied Bounded Waiting: Satisfied 7 December 2018 © Copyright Virtual University of Pakistan

7 © Copyright Virtual University of Pakistan
Semaphores 7 December 2018 © Copyright Virtual University of Pakistan

8 © Copyright Virtual University of Pakistan
Semaphores Synchronization tool Available in operating systems Semaphore S – integer variable that can only be accessed via two indivisible (atomic) operations, called wait and signal 7 December 2018 © Copyright Virtual University of Pakistan

9 © Copyright Virtual University of Pakistan
Semaphores wait(S){ while S 0 ; //no-op S--; } signal(S){ S++; 7 December 2018 © Copyright Virtual University of Pakistan

10 n-Processes CS Problem
Shared data: semaphore mutex = 1; Structure of Pi: do { critical section remainder section } while (1); wait(mutex); signal(mutex); 7 December 2018 © Copyright Virtual University of Pakistan

11 © Copyright Virtual University of Pakistan
Is it a Good Solution? Mutual Exclusion: Yes Progress: Yes Bounded Waiting: No 7 December 2018 © Copyright Virtual University of Pakistan

12 © Copyright Virtual University of Pakistan
Atomic Execution Uni-Processor Environment Inhibit interrupts before executing code for wait() and signal() Bus-based Multi-Processor Environment Lock the data bus Use a software solution 7 December 2018 © Copyright Virtual University of Pakistan

13 © Copyright Virtual University of Pakistan
Busy Waiting Processes wait by executing CPU instructions Problem? Wasted CPU cycles Solution? Modify the definition of semaphore 7 December 2018 © Copyright Virtual University of Pakistan

14 © Copyright Virtual University of Pakistan
Recap of Lecture Synchronization hardware Semaphores Semaphore based solutions for the critical section problem Busy waiting and modified definition of semaphore 7 December 2018 © Copyright Virtual University of Pakistan

15 Lecture 22 Syed Mansoor Sarwar
Operating Systems Lecture 22 Syed Mansoor Sarwar


Download ppt "Lecture 22 Syed Mansoor Sarwar"

Similar presentations


Ads by Google