CSE 451 Section Thursday, October 30. Questions from Lecture?

Slides:



Advertisements
Similar presentations
Operating Systems Semaphores II
Advertisements

1 Interprocess Communication 1. Ways of passing information 2. Guarded critical activities (e.g. updating shared data) 3. Proper sequencing in case of.
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.
Barber Shop 1 Barber Customer Queue. 2 C1C2C3 Barber Before Opening Customers waiting in queue.
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
EEE 435 Principles of Operating Systems Interprocess Communication Pt II (Modern Operating Systems 2.3)
CSE 451 Section February 3, Agenda Project comments Homework 3 review Sample exam questions.
Classic Synchronization Problems
1 CS 333 Introduction to Operating Systems Class 6 – Monitors and Message Passing Jonathan Walpole Computer Science Portland State University.
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.
Process Synchronization
Jonathan Walpole Computer Science Portland State University
1 Chapter 6: Concurrency: Mutual Exclusion and Synchronization Operating System Spring 2007 Chapter 6 of textbook.
02/25/2004CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
CS444/CS544 Operating Systems Classic Synchronization Problems 2/26/2007 Prof. Searleman
1 Interprocess Communication Race Conditions Two processes want to access shared memory at same time.
Jonathan Walpole Computer Science Portland State University
Computer Science 162 Discussion Section Week 3. Agenda Project 1 released! Locks, Semaphores, and condition variables Producer-consumer – Example (locks,
1 CS 333 Introduction to Operating Systems Class 5 – Semaphores and Classical Synchronization Problems Jonathan Walpole Computer Science Portland State.
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.
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.
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.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Chapter 6 – Process Synchronisation (Pgs 225 – 267)
1 Interprocess Communication (IPC) - Outline Problem: Race condition Solution: Mutual exclusion –Disabling interrupts; –Lock variables; –Strict alternation.
Synchronization III: Summary CPE Operating Systems
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 24 Critical Regions.
Problems with Semaphores Used for 2 independent purposes –Mutual exclusion –Condition synchronization Hard to get right –Small mistake easily leads to.
Synchronisation Examples
CSC 360 Instructor: Kui Wu More on Process Synchronization Semaphore, Monitor, Condition Variables.
Process Synchronization CS 360. Slide 2 CS 360, WSU Vancouver Process Synchronization Background The Critical-Section Problem Synchronization Hardware.
June 11, 2002Serguei A. Mokhov, 1 The Monitor COMP346 - Operating Systems Tutorial 7 Edition 1.2, June 15, 2002.
Chapter 71 Monitor for Reader/Writers  Synchronizes access if all processes follow.  If some don’t go through monitor and database is accessed directly,
CS 3340 Windows Programming. Course Evaluation Course Outcomes Not about the instructor Do it Today! 2.
Dining Philosophers Five philosophers sit around a table
CS703 – Advanced Operating Systems
PARALLEL PROGRAM CHALLENGES
Synchronization, part 3 Monitors, classical sync. problems
CS 3340 Windows Programming
Interprocess Communication (3)
Semaphores and Condition Variables
CSE451 Basic Synchronization Spring 2001
Chapter 5: Process Synchronization
Principles of Software Development
Synchronization, part 3 Monitors, classical sync. problems
CS399 New Beginnings Jonathan Walpole.
Critical section problem
CSE 451 Autumn 2003 Section 3 October 16.
Barbershop Example We can simulate a barbershop using semaphores.
CSE 451: Operating Systems Autumn Lecture 8 Semaphores and Monitors
Monitor Giving credit where it is due:
CSE 451: Operating Systems Autumn Lecture 7 Semaphores and Monitors
CS510 Operating System Foundations
Thread Synchronization including Mutual Exclusion
February 5, 2004 Adrienne Noble
CSE 153 Design of Operating Systems Winter 2019
N-Process Barrier (error 1)
CSE 451 Section 1/27/2000.
Problem: CFQ (Circular Fifo Queue)
FIRST SOLUTION Producer Process Consumer Process
Synchronization, part 3 Monitors, classical sync. problems
Synchronization CSE 2431: Introduction to Operating Systems
Presentation transcript:

CSE 451 Section Thursday, October 30

Questions from Lecture?

Questions from the Project?

Homeworks Barbershop Requirements: –Barber sleeps if no customers waiting –Customers leave if no chairs for waiting –Waiting customers can’t leave until haircut done. Solution: we use semaphores –Mutex = 1 –counting: barber_sleeping, customer_queue, cut_done

State Diagram SleepCut hair Check QueueWait for chairWait for cut Signal cut done If customers == 0 sleep if space

Barber Code wait(mutex) if (customers_waiting == 0) { signal(mutex); wait(barber_sleeping); wait(mutex); } customers_waiting--; signal(mutex); signal(customer_queue); do_cut_hair(); signal(cut_done);

Customer Code wait(mutex); if (customers_waiting == n) { signal(mutex); return; } customers_waiting++; if (customers_waiting == 1) { signal(barber_sleeping); } signal(mutex); wait(customer_queue); get_hair_cut(); wait(cut_done);

As a monitor monitor barbershop { int num_waiting; condition get_cut; condition barber_asleep; condition in_chair; condition cut_done;

Barber routine barber() { while (1); while (num_waiting == 0) { barber_asleep.wait(); } customer_waiting.signal(); in_chair.wait(); give_hait_cut(); cut_done.signal(); }

Customer routine custome () { if (num_waiting == n) { return; } if (num_waiting == 0) { barber_asleep.signal(); } customer_waiting.wait(); in_char.signal(); get_hair_cut(); cut_done.wait(); }

File access Requirements –Each file has a number N, and the sum of the PID’s of the processes accessing the file must be <= N. –Processes wishing to access the file block until the file is available

File Monitor monitor file_access { condition wake_up; int max_sum; int curr_sum access(int pid) { while (curr_sum + pid > max_sum) wake_up.wait(); curr_sum += pid; } release(int pid) { curr_sum = curr_sum - pid; wake_up.broadcast(); }

What’s wrong How long can a process wait? What if the accesor doesn’t want to wait? Do we need to wake everybody up every time?

Cigarette Smokers semaphore agent = 1; sempahore tobacco_paper = 1; sempahore paper_matches = 1; sempahore matches_tobacco = 1; agent() { while (1) { signal(paper_matches); wait(agent); } tobacco_guy() { while(1) { wait(paper_matches); signal(agent); }

Memory Management - paging

Memory management - segments

Memory management - both

Why both?

Unixex bathroom (1) monitor unisex_bathroom: int num_male_in; int num_female_in; condition male_wait; condition female_wait;

Men enter male_enter() { while (num_female_in != 0) { male_wait.wait(); } num_male_in++; } male_exit() { num_male_in--; if (num_male_in == 0) { female_wait.broadcast(); } }

Unixex bathroom (2) monitor unisex_bathroom: int num_male_in; int num_female_in; int num_male_wait; int num_female_wait; condition male_wait; condition female_wait; boolean male_in;

Women female_enter() { num_female_wait++; if (num_male_wait > 0) female_wait.wait(); while (num_male_in != 0) female_wait.wait(); num_female_wait--; num_female_in++; }