1 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.

Slides:



Advertisements
Similar presentations
Operating Systems Semaphores II
Advertisements

Operating Systems: Monitors 1 Monitors (C.A.R. Hoare) higher level construct than semaphores a package of grouped procedures, variables and data i.e. object.
Operating Systems Mehdi Naghavi Winter 1385.
Barber Shop 1 Barber Customer Queue. 2 C1C2C3 Barber Before Opening Customers waiting in queue.
Ch 7 B.
CSC321 Concurrent Programming: §4 Semaphores 1 Section 4 Semaphores.
CSE 451 Section February 3, Agenda Project comments Homework 3 review Sample exam questions.
Classic Synchronization Problems
02/19/2010CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
Review: Producer-Consumer using Semaphores #define N 100// number of slots in the buffer Semaphore mutex = 1;// controls access to critical region Semaphore.
1 CS 333 Introduction to Operating Systems Class 5 – Classical IPC Problems Jonathan Walpole Computer Science Portland State University.
1 Thursday, June 22, 2006 "I think I've got the hang of it now.... :w :q :wq :wq! ^d X exit ^X^C ~. ^[x X Q :quitbye CtrlAltDel ~~q :~q logout save/quit.
1 CS 333 Introduction to Operating Systems Class 5 – Semaphores and Classical Synchronization Problems Jonathan Walpole Computer Science Portland State.
Semaphores. Announcements No CS 415 Section this Friday Tom Roeder will hold office hours Homework 2 is due today.
1 OMSE 510: Computing Foundations 7: More IPC & Multithreading Chris Gilmore Portland State University/OMSE Material Borrowed from Jon Walpole’s lectures.
Semaphores, mutexes and condition variables. semaphores Two types – Binary – 0 or 1 – Counting 0 to n Wait – decrements > 0 forces a wait Post or signal.
Jonathan Walpole Computer Science Portland State University
Monitors CSCI 444/544 Operating Systems Fall 2008.
Semaphores The producer-consumer problem using semaphores.
1 Interprocess Communication Race Conditions Two processes want to access shared memory at same time.
Jonathan Walpole Computer Science Portland State University
CY2003 Computer Systems Lecture 11 Review Lecture.
18/02/08Week 21 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:
More Synchronisation Last time: bounded buffer, readers-writers, dining philosophers Today: sleeping barber, monitors.
5.4 Which of the following scheduling algorithms could result in starvation? a. First-come, first-served b. Shortest job first c. Round robin d. Priority.
Semaphores. Readings r Silbershatz: Chapter 6 Mutual Exclusion in Critical Sections.
Outline Monitors Barrier synchronization The sleeping barber problem
Operating Systems Review for Chap.6 & 7 Hung Q. Ngo KyungHee University Spring 2009
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Classical problems.
Semaphores and Bounded Buffer. Semaphores  Semaphore is a type of generalized lock –Defined by Dijkstra in the last 60s –Main synchronization primitives.
Thread Synchronization Tutorial #8 CPSC 261. A thread is a virtual processor Each thread is provided the illusion that it owns a core – Copy of the registers.
Outline  Monitors o Monitors in Java  Barrier synchronization  The sleeping barber problem  Readers and Writers 1 Ben-Gurion University Operating Systems,
Homework Assignment #2 J. H. Wang Oct. 17, 2007.
Synchronization, part 3 Monitors, classical sync. problems
Synchronizing Threads with Semaphores
Chapter 2 Chapter 2: Processes & Threads Part 2 Interprocess Communication (IPC) & Synchronization.
1 Interprocess Communication (IPC) - Outline Problem: Race condition Solution: Mutual exclusion –Disabling interrupts; –Lock variables; –Strict alternation.
Dining Philosophers (1) Philosophers eat/think Eating needs 2 forks Pick one fork at a time How to prevent deadlock.
CSE 451 Section Thursday, October 30. Questions from Lecture?
CSC321 Concurrent Programming: §4 Semaphores 1 Section 4 Semaphores.
Operating Systems COMP 4850/CISG 5550 Interprocess Communication, Part II Dr. James Money.
Process Synchronization CS 360. Slide 2 CS 360, WSU Vancouver Process Synchronization Background The Critical-Section Problem Synchronization Hardware.
CS 3340 Windows Programming. Course Evaluation Course Outcomes Not about the instructor Do it Today! 2.
Semaphores Reference –text: Tanenbaum ch
CS 311/350/550 Semaphores. Semaphores – General Idea Allows two or more concurrent threads to coordinate through signaling/waiting Has four main operations.
Synchronization, part 3 Monitors, classical sync. problems
Announcement server: server.o common.o $(CC) -o server server.o common.o $(LIBS) -lsock -lpthread and change it to: server: server.o common.o threadpool.o.
Lecture 6 Interprocess Communication with Homework#2
Dining Philosophers Five philosophers sit around a table
Semaphores Reference text: Tanenbaum ch
PARALLEL PROGRAM CHALLENGES
Synchronization, part 3 Monitors, classical sync. problems
CS 3340 Windows Programming
2.4 Classic IPC Problems Dining philosophers Readers and writers
Synchronization, part 3 Monitors, classical sync. problems
Lecture 13: Producer-Consumer and Semaphores
Chapter 5: Process Synchronization
Principles of Software Development
Synchronization, part 3 Monitors, classical sync. problems
Synchronization, part 3 Monitors, classical sync. problems
CS399 New Beginnings Jonathan Walpole.
Critical section problem
Barbershop Example We can simulate a barbershop using semaphores.
CS510 Operating System Foundations
Lecture 13: Producer-Consumer and Semaphores
More IPC B.Ramamurthy 4/15/2019.
Semaphores Reference text: Tanenbaum ch
Synchronization, Part 2 Semaphores
Synchronization, part 3 Monitors, classical sync. problems
Presentation transcript:

1 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 (as illustrated in the picture) 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.

2 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 leave, which exits. Barber threads should invoke cutHair. When the barber invokes cutHair there should be exactly one thread invoking getHairCut concurrently.

3 Sleeping Barber Solution void customer (void){ down(mutex); if (counts==n+1) { up(mutex); leave(); } counts +=1; up(mutex); up(customer); down(barber); getHairCut(); down(mutex); counts -=1; up(mutex); } void barber (void){ down(customer); up(barber); cutHair(); } int counts = 0; mutex = Semaphore(1); customer = Semaphore(0); barber = Semaphore(0);