lecture11-chapter05

lecture11-chapter05 - (void){ semWait(mutex); if...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
Operating Systems Lecture 11: Barber Shop. Readers/Writers Anda Iamnitchi anda@cse.usf.edu 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Sleeping Barber Problem There is one barber, and n chairs for waiting customers If there are no customers, then the barber sits in his chair and sleeps When a new customer arrives and the barber is sleeping, then he will wakeup the barber When a new customer arrives, and the barber is busy, then he will sit on the chairs if there is any available, otherwise (when all the chairs are full) he will leave.
Background image of page 2
3 Barber Shop Hints Consider the following: Customer threads should invoke a function named getHairCut . If a customer thread arrives when the shop is full, it can invoke balk , which exits. Barber threads should invoke cutHair . When the barber invokes cutHair there should be exactly one thread invoking getHairCut concurrently.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Sleeping Barber Solution void customer
Background image of page 4
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 6
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 8
Background image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: (void){ semWait(mutex); if (customers==n+1) { semSignal(mutex); balk(); } customers +=1; semSignal(mutex); semSignal(customer); semWait(barber); getHairCut(); semWait(mutex); customers =1; semSignal(mutex); } void barber (void){ semWait(customer); semSignal(barber); cutHair(); } int customers = 0; mutex = Semaphore(1); customer = Semaphore(0); barber = Semaphore(0); Readers/Writers Problem A data area is shared among many processes Some processes only read the data area, some only write to the area Conditions to satisfy: 1. Multiple readers may read the file at once. 2. Only one writer at a time may write 3. If a writer is writing to the file, no reader may read it. Readers have Priority Writers have Priority Writers have Priority (cont) Writers Have Priority (on one slide)...
View Full Document

Page1 / 9

lecture11-chapter05 - (void){ semWait(mutex); if...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online