1 / 116

Semaphores

Semaphores. Ref: William Stallings,Galvin, Naresh Chauhan G.Anuradha. Popular tool for process synchronization Used to protect any resource such as global shared memory that needs to be accessed and updated by many processes

chip
Download Presentation

Semaphores

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Semaphores Ref: William Stallings,Galvin, Naresh Chauhan G.Anuradha

  2. Popular tool for process synchronization Used to protect any resource such as global shared memory that needs to be accessed and updated by many processes Analogy- allotment of seminar room for various activites of college. What is a semaphore? 9/1/2014

  3. Principle of a Semaphore For signaling semaphores are used • For sending a signal semSignal (s) is used • For receiving a signal semWait(s) is used • First defined by Dijkstra • Semaphore is a variable • A semaphore may be initialized to a nonnegative integer value. • The semWait operation decrements the semaphore value. • The semSignal operation increments the semaphore value.

  4. wait (S) { while S <= 0 ; // no-op S--; } signal (S) { S++; } 9/1/2014

  5. Definition of semaphore

  6. Types of Semaphores • Binary semaphore:-takes value 0 and 1-used for resource having a single instance • Counting Semphore:- when there are more than one process. • Mutex:-similar to binary semaphore but the key difference is that the mutex is locked and unlocked by the same process

  7. Classical Synchronization problems • Producer consumer problem • Reader-writer problem • Barber shop • Dining philosopher

  8. I. Producer-Consumer Imagine a chef cooking items and putting them onto a conveyor belt 43 43

  9. Producer-Consumer Imagine a chef cooking items and putting them onto a conveyor belt Now imagine many such chefs! 44

  10. Producer-Consumer Imagine a chef cooking items and putting them onto a conveyor belt Now imagine many such chefs! 45

  11. Producer-Consumer Imagine a chef cooking items and putting them onto a conveyor belt Now imagine many such chefs! Now imagine a customer picking items off the conveyor belt 46

  12. Producer-Consumer Imagine a chef cooking items and putting them onto a conveyor belt Now imagine many such chefs! Now imagine many such customers picking items off the conveyor belt! 47

  13. Producer-Consumer Imagine a chef cooking items and putting them onto a conveyor belt Now imagine many such chefs! Now imagine many such customers picking items off the conveyor belt! 48

  14. Producer-Consumer Chef = Producer Customer = Consumer insertPtr removePtr 49

  15. Producer-Consumer Chef = Producer Customer = Consumer insertPtr removePtr 50

More Related