FIRST SOLUTION Producer Process Consumer Process

Slides:



Advertisements
Similar presentations
Stuff  Exam timetable now available  Class back in CS auditorium as of Wed, June 4 th  Assignment 2, Question 4 clarification.
Advertisements

Task Synchronization Prepared by: Jamil Alomari Suhaib Bani Melhem
Process Synchronization CS 502 Spring 99 WPI MetroWest/Southboro Campus.
Classical Problems of Concurrency
Operating Systems Process Synchronization. Too Much Pizza 3:00 3:05 3:10 3:15 3:20 3:25 3:30 Person A Look in fridge. Pizza! Leave for store. Arrive at.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization.
CIS 415 Process Synchronization Background The Critical-Section Problem Software Solutions Semaphores Hardware Support Classical Problems of Synchronization.
Synchronization April 14, 2000 Instructor Gary Kimura Slides courtesy of Hank Levy.
Semaphores The producer-consumer problem using semaphores.
Operating Systems Process Synchronization. Too Much Pizza 3:00 3:05 3:10 3:15 3:20 3:25 3:30 Person A Look in fridge. Pizza! Leave for store. Arrive at.
CS444/CS544 Operating Systems Classic Synchronization Problems 2/26/2007 Prof. Searleman
Operating Systems Process Synchronization (Ch )
Operating System I Process Synchronization. Too Much Pizza 3:00 3:05 3:10 3:15 3:20 3:25 3:30 Person A Look in fridge. Pizza! Leave for store. Arrive.
Higher Level Mechanisms for Building Critical Sections zSemaphores yVery primitive (Specifying direct start and stop of threads) ySimple (Hard to program.
More Synchronisation Last time: bounded buffer, readers-writers, dining philosophers Today: sleeping barber, monitors.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 23 Classic Synchronization.
Midterm 1 – Wednesday, June 4  Chapters 1-3: understand material as it relates to concepts covered  Chapter 4 - Processes: 4.1 Process Concept 4.2 Process.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization.
Silberschatz and Galvin  Operating System Concepts Module 6: Process Synchronization Background The Critical-Section Problem Synchronization.
1 Previous Lecture Review n Concurrently executing threads often share data structures. n If multiple threads are allowed to access shared data structures.
1 Chapter 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Special Machine Instructions for Synchronization Semaphores.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization.
1 CS.217 Operating System By Ajarn..Sutapart Sappajak,METC,MSIT Chapter 7 Process Synchronization Slide 1 Chapter 7 Process Synchronization.
Silberschatz and Galvin  Operating Systems Overview D. Manivannan Department of Computer Science University of Kentucky.
Process Synchronization Concurrent access to shared data may result in data inconsistency. Maintaining data consistency requires mechanisms to ensure the.
1 Lecture 8: Concurrency: Mutual Exclusion and Synchronization(cont.) Advanced Operating System Fall 2009.
Synchronization III: Summary CPE Operating Systems
IT 344: Operating Systems Winter 2008 Module 7 Semaphores and Monitors
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.
CSE Operating System Principles Synchronization.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 22 Semaphores Classic.
Producer-Consumer Problem David Monismith cs550 Operating Systems.
1 Advanced Operating Systems - Fall 2009 Lecture 7 – February 2, 2009 Dan C. Marinescu Office: HEC 439 B. Office hours:
Chapter 71 Monitor for Reader/Writers  Synchronizes access if all processes follow.  If some don’t go through monitor and database is accessed directly,
Classic problems of Synchronization : Producers/Consumers problem: The producers/ consumers problem may be stated as follows: Given a set of cooperating.
Chapter 6 Synchronization Dr. Yingwu Zhu. The Problem with Concurrent Execution Concurrent processes (& threads) often access shared data and resources.
Web Server Architecture Client Main Thread for(j=0;j
6.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles 6.5 Semaphore Less complicated than the hardware-based solutions Semaphore S – integer.
Synchronization Semaphores
Semaphores Synchronization tool (provided by the OS) that does not require busy waiting. Logically, a semaphore S is an integer variable that, apart from.
Semaphore Synchronization tool that provides more sophisticated ways (than Mutex locks) for process to synchronize their activities. Semaphore S – integer.
Chapter 5: Process Synchronization
Auburn University COMP 3500 Introduction to Operating Systems Synchronization: Part 4 Classical Synchronization Problems.
PARALLEL PROGRAM CHALLENGES
Chapter 5: Process Synchronization – Part II
Chapter 5: Process Synchronization
Interprocess Communication (3)
Chapter 7: Process Synchronization
Chapter 6-7: Process Synchronization
CSE451 Basic Synchronization Spring 2001
                                                                                                                                                                 
Chapter 5: Process Synchronization
Chapter 5: Process Synchronization
Chapter 5: Process Synchronization (Con’t)
CS 153 Design of Operating Systems Winter 2016
Chapter 5: Process Synchronization
Semaphore Originally called P() and V() wait (S) { while S <= 0
Chapter 5: Process Synchronization
Synchronization Hank Levy 1.
Chapter 7: Synchronization Examples
CSE 451: Operating Systems Autumn Lecture 8 Semaphores and Monitors
CSE 451: Operating Systems Autumn Lecture 7 Semaphores and Monitors
Synchronization Hank Levy 1.
Chapter 7: Synchronization Examples
CSE 153 Design of Operating Systems Winter 2019
Chapter 5: Process Synchronization
Problem: CFQ (Circular Fifo Queue)
Synchronization CSE 2431: Introduction to Operating Systems
Presentation transcript:

FIRST SOLUTION Producer Process Consumer Process #define N 10 // Queue Size #define NUM_REPEAT 1,000,000 // Number of items to be generated semaphore MUTEX 1 // binary semaphore SM: a pointer to the queue in shared memory SMnum_element = 0; // # of the random # produced to the queue Producer Process Consumer Process int i; // loop counter int new_item; // the new random # int tail = 0; // the position for the new # for (i=0; i < NUM_REPEAT; i++) { new_item = rand( ); if(SMnum_element < N) wait(MUTEX); SM[tail] = new_item; SMnum_element ++; signal(MUTEX); tail ++; if (tail  N) tail = 0; } else { i--; } int top = 0; // the position for the new # if(SMnum_element > 0) new_item = SM[top]; SMnum_element --; top ++; if (top  N) top = 0; FIRST SOLUTION

SECOND SOLUTION Producer Process Consumer Process #define N 10 // Queue Size #define NUM_REPEAT 1,000,000 // Number of items to be generated semaphore MUTEX 1 // binary semaphore semaphore EMPTY N // counting semaphore semaphore FULL 0 // counting semaphore SM: a pointer to the queue in shared memory Producer Process Consumer Process int i; // loop counter int new_item; // the new random # int tail = 0; // the position for the new # for (i=0; i < NUM_REPEAT; i++) { wait(EMPTY); new_item = rand( ); wait(MUTEX); SM[tail] = new_item; signal(MUTEX); tail ++; if (tail  N) tail = 0; signal(FULL); } int top = 0; // the position for the new # wait(FULL); new_item = SM[top]; top ++; if (top  N) top = 0; signal(EMPTY);