1 / 6

CS 311- Fall 2010

CS 311- Fall 2010. Semaphores. Semaphores – General Idea. Allows two or more concurrent threads to coordinate through signaling/waiting Has four main operations initialize, getvalue , increment ( signal ), decrement ( wait )

Download Presentation

CS 311- Fall 2010

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. CS 311- Fall 2010 Semaphores

  2. Semaphores – General Idea • Allows two or more concurrent threads to coordinate through signaling/waiting • Has four main operations • initialize, getvalue, increment (signal), decrement (wait) • The thread who “locks” is not necessarily the thread who “unlocks” • Those blocked-waiting are always put in a list

  3. Semaphores – Signal/Wait • Integer counter • coordination and synchronization depends on this value • sem_wait • decrements the counter • then blocked if counter is < 0 • thread placed in the blocked list • sem_signal • increments the counter • unblocks the next thread in the blocked list

  4. Binary Semaphores • Binary Semaphores • Counter can only be one or zero • Access to the critical section is one at a time • Similar to a mutex lock

  5. Counting Semaphores • Counter can be any integer value at any time • Used for more complex synchronization • Examples • Prioritizing access to the critical section • Producer/Consumer model with a bound buffer • Multiple counting semaphores can be used to coordinate multiple Readers/Writers

  6. Semaphore Example - POSIX

More Related