semaphore by xiuliliaofz

VIEWS: 20 PAGES: 4

									      The operators P and V
• P (request)
  – P (sem)
       – Sem - -
       – If Sem < 0
            » Block on Sem


  – V (sem)
       – Sem ++
       – If Sem < =0
            » Wake up next process
      Types of Semaphores
• Binary semaphore – maximum value of 1



• Counting semaphore – maximum value
  other than 1
  Producer/Consumer Problem
• Set of 10 buffers
• Producer – fills a buffer with information
• Consumer – empties the buffer when it is
  full
    Producer/Consumer Problem
•   Producer     •   Consumer
•   P (empty)    •   P (full)
•   P (mutex)    •   P (mutex)
•   <CS>         •   <CS>
•   V (mutex)    •   V (mutex)
•   V (full)     •   V (empty)

								
To top