1 / 6

Semaphores

Semaphores. Race Condition. Occurs when multiple processes access and manipulate the same data concurrently The outcome of the execution depends on the particular order in which the access takes place

aleta
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

  2. Race Condition • Occurs when multiple processes access and manipulate the same data concurrently • The outcome of the execution depends on the particular order in which the access takes place • Ex. Two processes try to write to the same memory location, which one should go ahead and write?

  3. To enforce execution Order • Process busy waits • While (CONDITION_NOT_SATISFIED); • Process goes to sleep until being explicitly woke up by others • Semaphores

  4. Semaphores • A lock that is associated with a counter value • Counter: Zero or positive number

  5. POSIX Semaphores • #include <semaphore.h> • sem_t sem_name; • sem_init(sem_t *sem, int pshared, unsigned int value); • sem_wait(&sem_name); • sem_post(&sem_name); • sem_getvalue(sem_t *sem, int *valp); • sem_destroy(&sem_name); • gcc program.c -lrt

  6. Links http://www.csc.villanova.edu/~mdamian/threads/posixsem.html System V Semaphores API: http://beej.us/guide/bgipc/output/html/multipage/semaphores.html

More Related