lecture11-chapter05

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

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

Operating Systems Operating Systems Lecture 11: Lecture 11: Barber Shop. Readers/Writers Barber Shop. Readers/Writers Anda Iamnitchi [email protected] 1

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

View Full Document
2 Sleeping Barber Problem 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.
3 Barber Shop Hints 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.

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

View Full Document
4 Sleeping Barber Solution Sleeping Barber Solution void

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

View Full Document

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: customer (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 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 Readers have Priority Writers have Priority Writers have Priority Writers have Priority (cont’) Writers have Priority (cont’) Writers Have Priority Writers Have Priority (on one slide) (on one slide)...
View Full Document

This note was uploaded on 02/18/2012 for the course COP 4600 taught by Professor Andaiamnitchi during the Fall '08 term at University of South Florida.

Page1 / 9

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

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

View Full Document
Ask a homework question - tutors are online