4330/6310 THIRD ASSIGNMENT Spring 2015. The problem (I) A post office with a single queue and several nameless clerks: Clerk 0 Customers waiting Clerk.

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.
1 Processes and Threads Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
More on Processes Chapter 3. Process image _the physical representation of a process in the OS _an address space consisting of code, data and stack segments.
Synchronization and Deadlocks
More on Semaphores, and Classic Synchronization Problems CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han.
CAS3SH3 Midterm Review. The midterm 50 min, Friday, Feb 27 th Materials through CPU scheduling closed book, closed note Types of questions: True & False,
Global Environment Model. MUTUAL EXCLUSION PROBLEM The operations used by processes to access to common resources (critical sections) must be mutually.
CS Lecture 4 Programming with Posix Threads and Java Threads George Mason University Fall 2009.
CSCC69: Operating Systems
Chapter 2 Processes and Threads
EEE 435 Principles of Operating Systems Interprocess Communication Pt II (Modern Operating Systems 2.3)
Cpr E 308 Spring 2004 Recap for Midterm Introductory Material What belongs in the OS, what doesn’t? Basic Understanding of Hardware, Memory Hierarchy.
1 Threads CSCE 351: Operating System Kernels Witawas Srisa-an Chapter 4-5.
5.6 Semaphores Semaphores –Software construct that can be used to enforce mutual exclusion –Contains a protected variable Can be accessed only via wait.
1 Semaphores Special variable called a semaphore is used for signaling If a process is waiting for a signal, it is suspended until that signal is sent.
Semaphores. Announcements No CS 415 Section this Friday Tom Roeder will hold office hours Homework 2 is due today.
CS470 Lab 4 TA Notes. Objective Simulate the activities of a producer and consumer – Page 326 Use thread synchronization to solve the producer-consumer.
Components and Organization of Discrete-event Simulation Model
Inter Process Communication:  It is an essential aspect of process management. By allowing processes to communicate with each other: 1.We can synchronize.
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.
Project #3, Threads and Synchronization CS-3013 A-term Project #3 Threads and Synchronization CS-3013, Operating Systems A-term 2009 Due Tuesday,
Chapter 6 – Concurrent Programming Outline 6.1 Introduction 6.2Monitors 6.2.1Condition Variables 6.2.2Simple Resource Allocation with Monitors 6.2.3Monitor.
Client Server Design Alternatives© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid.
1 Chapter 6: Concurrency: Mutual Exclusion and Synchronization Operating System Spring 2007 Chapter 6 of textbook.
The Structure of the “THE” -Multiprogramming System Edsger W. Dijkstra Jimmy Pierce.
1 Interprocess Communication Race Conditions Two processes want to access shared memory at same time.
Using Two Queues. Using Multiple Queues Suspended Processes Processor is faster than I/O so all processes could be waiting for I/O Processor is faster.
Computer Science 162 Discussion Section Week 3. Agenda Project 1 released! Locks, Semaphores, and condition variables Producer-consumer – Example (locks,
1 Race Conditions/Mutual Exclusion Segment of code of a process where a shared resource is accessed (changing global variables, writing files etc) is called.
Pthread (continue) General pthread program structure –Encapsulate parallel parts (can be almost the whole program) in functions. –Use function arguments.
CS510 Concurrent Systems Introduction to Concurrency.
Nachos Phase 1 Code -Hints and Comments
CGS 3763 Operating Systems Concepts Spring 2013 Dan C. Marinescu Office: HEC 304 Office hours: M-Wd 11: :30 AM.
1 Processes Chapter Processes 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
The Third Assignment COSC 4330/6310 Spring Implementing delays To be able to test the semaphores, we must run the program in real time To be able.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Classical problems.
1 Announcements The fixing the bug part of Lab 4’s assignment 2 is now considered extra credit. Comments for the code should be on the parts you wrote.
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.
Multiprogramming. Readings r Silberschatz, Galvin, Gagne, “Operating System Concepts”, 8 th edition: Chapter 3.1, 3.2.
1 Program5 Due Friday, March Prog4 user_thread... amount = … invoke delegate transact (amount)... mainThread... Total + = amount … user_thread...
2001 Networking Operating Systems (CO32010) 1. Operating Systems 2. Processes and scheduling 4.
Concurrency in Java Brad Vander Zanden. Processes and Threads Process: A self-contained execution environment Thread: Exists within a process and shares.
CPS110: Implementing threads Landon Cox. Recap and looking ahead Hardware OS Applications Where we’ve been Where we’re going.
Lecture 5 Barriers and MPI Introduction Topics Barriers Uses implementations MPI Introduction Readings – Semaphore handout dropboxed January 24, 2012 CSCE.
1 Interprocess Communication (IPC) - Outline Problem: Race condition Solution: Mutual exclusion –Disabling interrupts; –Lock variables; –Strict alternation.
Process Description and Control Chapter 3. Source Modified slides from Missouri U. of Science and Tech.
Thread Synchronization including Mutual Exclusion In Java synchronized keyword Monitor or Lock with conditions Semaphore.
Problems with Semaphores Used for 2 independent purposes –Mutual exclusion –Condition synchronization Hard to get right –Small mistake easily leads to.
Processes Creation and Threads. Shared Resource Example The console is just a place where text can be printed by the application currently running. Program.
More Discussions on hw5 Timer interrupts –called ticks. ISR called tick handler Kernel uses ticks for: –time keeping, incrementing the global system time.
Chapter 71 Monitor for Reader/Writers  Synchronizes access if all processes follow.  If some don’t go through monitor and database is accessed directly,
CS510 Concurrent Systems Jonathan Walpole. Introduction to Concurrency.
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Mutual Exclusion Mutexes, Semaphores.
Process Management Process Concept Why only the global variables?
PROCESS MANAGEMENT IN MACH
Process Synchronization
CS 3340 Windows Programming
CGS 3763 Operating Systems Concepts Spring 2013
Python Lesson 3 Mr. Kalmes.
System Structure and Process Model
Distributed systems II A polynomial local solution to Mutual Exclusion
Outline Distributed Mutual Exclusion Introduction Performance measures
MAT 4830 Mathematical Modeling
Thread Synchronization including Mutual Exclusion
Process Synchronization
Monitors and Inter-Process Communication
Chapter 3: Process Management
Presentation transcript:

4330/6310 THIRD ASSIGNMENT Spring 2015

The problem (I) A post office with a single queue and several nameless clerks: Clerk 0 Customers waiting Clerk 1 …

The problem (II) Can represent the n clerks by a single semaphore  post_office Its initial value will be the total number of clerks helping customers Its current value will indicate the number of idle clerks

Your program (I) Main program will  Read a line with a customer's name, arrival_delay, and service_time  Sleep for arrival_delay seconds  Fork a child Wait until all children have terminated Print statistics

Your program (II) Your child processes will  Print a message  Do a P() on the post_office semaphore  Print a message  Sleep for service_time seconds  Print a message  Do a V() on the post_office semaphore  Terminate by doing _exit(0);

Collecting statistics Before terminating, your program should display:  The total number of customers that got serviced Can be maintained by the main program  The number of customers that did not have to wait Will require some extra coding  The number of customers that had to wait Trivial

Knowing if a customer had to wait A customer process will wait if all clerks were busy when it arrived at the post office  Easiest way is to check the value of the semaphore post office sem_getvalue(mysem,&value);

Customer processes revisited (I) Your child processes will  Print a message  Get the current value of the post_office  If all clerks are busy increment the number of customers who had to wait  Do a P() on the post_office semaphore  Print a message  Sleep for service_time seconds  Print a message  Do a V() on the post office semaphore  Terminate by doing _exit(0);

Using a shared variable The number of customers that have to wait is  A global variable shared by all your processes  Must be stored in a shared memory segment  Must be accessed in mutual exclusion Add a second semaphore ("mutex") to your program

Customer processes revisited (II) Your child processes will  Print a message  Get the current value of the post_office semaphore  If all clerks are busy then Do a P() on a mutex Increment the number of customers who had to wait Do a V() on a mutex  Do a P() on the post_office semaphore  Print a message  Sleep for service_time seconds  Print a message  Do a V() on the post office semaphore  Terminate by doing _exit(0);