1 / 10

SCRIBE OF DATE:26-02-2014

SCRIBE OF DATE:26-02-2014. Sathu Hareesh Babu 11CS10039. Producer Consumer Problem-Tasks. We must ensure proper synchronization - Stop the consumer when buffer is empty. - Stop the producer when buffer is full. We must ensure mutual exclusion

eron
Download Presentation

SCRIBE OF DATE:26-02-2014

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. SCRIBE OF DATE:26-02-2014 Sathu Hareesh Babu 11CS10039

  2. Producer Consumer Problem-Tasks • We must ensure proper synchronization - Stop the consumer when buffer is empty. - Stop the producer when buffer is full. • We must ensure mutual exclusion - That is,we should avoid race condition. • Piggybank the wakeup signals • Avoid busy waiting.

  3. Semaphore • Semaphore is a widely used synchronization tool. • Busy waiting is not required - CPU is not held unnecessarily while the process is waiting. • A semaphore S is a data structure with • An integer variable S.value • A queue S.list of processes(shared variable) • The data structure can only be accessed by two atomic operations wait(S) and signal(S)(also called down(S),P(S) and Up(S),V(S).

  4. Semaphore • Value of Semaphore S = Value of the integer S.value. • Semaphore data structure typedefstruct{ int value; struct process *list; }semaphore

  5. Semaphore Wait(S) • Wait(S) S<= Semaphore variable • When a process P executes the wait(S) and finds • S == 0 • Process must wait => block() • Switch from running to waiting state • Places the process into a waiting queue associated with S

  6. Semaphore • Wait(S) • P executes wait(S) if(s > 0) s-- ; else if s == 0  P waits(placed in waiting queue)

  7. Semaphore Signal(S) • Signal(S) When a process P executes the signal S. • Check, if some other process Q is waiting on the semaphore S • Wakeup(Q) • Wakeup(Q) changes the process from waiting to ready state

  8. Semaphore • Signal(S) if(s>0) s++; else if s==0 if no process waiting -> s++ else wake one of the processes up.

  9. Semaphore(wait and signal) • Implementation of wait; wait(semaphore *S) { S->value--; if (S->value < 0) { add this process to S->list; block(); } } PCB List

  10. Semaphore(wait and signal) • Implementation of signal: signal(semaphore *S) { S->value++; if (S->value <= 0) { remove a process P from S->list; wakeup(P); } }

More Related