CS 3340 Windows Programming

Slides:



Advertisements
Similar presentations
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.
Advertisements

Barber Shop 1 Barber Customer Queue. 2 C1C2C3 Barber Before Opening Customers waiting in queue.
Operating Systems: A Modern Perspective, Chapter 8 Slide 8-1 Copyright © 2004 Pearson Education, Inc.
1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:
CH7 discussion-review Mahmoud Alhabbash. Q1 What is a Race Condition? How could we prevent that? – Race condition is the situation where several processes.
1 Semaphores and Monitors CIS450 Winter 2003 Professor Jinhua Guo.
Classic Synchronization Problems
5.6 Semaphores Semaphores –Software construct that can be used to enforce mutual exclusion –Contains a protected variable Can be accessed only via wait.
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 CS 333 Introduction to Operating Systems Class 5 – Classical IPC Problems Jonathan Walpole Computer Science Portland State University.
Semaphores. Announcements No CS 415 Section this Friday Tom Roeder will hold office hours Homework 2 is due today.
Jonathan Walpole Computer Science Portland State University
Chapter 6 – Concurrent Programming Outline 6.1 Introduction 6.2Monitors 6.2.1Condition Variables 6.2.2Simple Resource Allocation with Monitors 6.2.3Monitor.
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:
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.
Nachos.
Nachos Phase 1 Code -Hints and Comments
Tutorial 5 Even More Synchronization! presented by: Antonio Maiorano Paul Di Marco.
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.
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.
CS 3340 Windows Programming Prog4 Test Program5 Due Friday, March 27.
4061 Session 21 (4/3). Today Thread Synchronization –Condition Variables –Monitors –Read-Write Locks.
11/18/20151 Operating Systems Design (CS 423) Elsa L Gunter 2112 SC, UIUC Based on slides by Roy Campbell, Sam.
1 Program5 Due Friday, March Prog4 user_thread... amount = … invoke delegate transact (amount)... mainThread... Total + = amount … user_thread...
11/21/20151 Operating Systems Design (CS 423) Elsa L Gunter 2112 SC, UIUC Based on slides by Roy Campbell, Sam.
1 Prog4 user_thread... amount = … invoke delegate transact (amount)... mainThread... Total + = amount … user_thread... amount = … invoke delegate transact.
Problems with Semaphores Used for 2 independent purposes –Mutual exclusion –Condition synchronization Hard to get right –Small mistake easily leads to.
4330/6310 THIRD ASSIGNMENT Spring The problem (I) A post office with a single queue and several nameless clerks: Clerk 0 Customers waiting Clerk.
CS 3340 Windows Programming. Course Evaluation Course Outcomes Not about the instructor Do it Today! 2.
Homework-6 Questions : 2,10,15,22.
Web Server Architecture Client Main Thread for(j=0;j
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Mutual Exclusion Mutexes, Semaphores.
pThread synchronization
Tutorial 2: Homework 1 and Project 1
CS703 - Advanced Operating Systems
Synchronization Condition Variables and Monitors
Dining Philosophers Five philosophers sit around a table
Synchronization, part 3 Monitors, classical sync. problems
Recursion CSC 202.
2.4 Classic IPC Problems Dining philosophers Readers and writers
CS533 Concepts of Operating Systems Class 3
Monitors, Condition Variables, and Readers-Writers
Day 13 Concurrency.
Day 15 Concurrency.
Critical Section and Critical Resources
Chapter 5: Process Synchronization
Principles of Software Development
Critical Section and Critical Resources
Multithreading.
TIARA Thread Management
Synchronization, part 3 Monitors, classical sync. problems
Critical section problem
Dr. Mustafa Cem Kasapbaşı
Implementing Mutual Exclusion
Barbershop Example We can simulate a barbershop using semaphores.
CS533 Concepts of Operating Systems Class 3
CSE 451: Operating Systems Autumn Lecture 8 Semaphores and Monitors
Implementing Mutual Exclusion
CSE 451: Operating Systems Autumn Lecture 7 Semaphores and Monitors
CS510 Operating System Foundations
Chapter 6 Synchronization Principles
CSE 451: Operating Systems Winter Module 7 Semaphores and Monitors
CS333 Intro to Operating Systems
True / False Variables.
EECE.4810/EECE.5730 Operating Systems
Synchronization, part 3 Monitors, classical sync. problems
Hair Removal Methods: What's Effective and What's Not.
Review The Critical Section problem Peterson’s Algorithm
Presentation transcript:

CS 3340 Windows Programming

Test 3: Threading Barbershop Similar to Prog5 (Reader & Writer) Tuesday, April 4 Lab 206 80 minutes Initial solution

One Barber with one Customer Queue Barber Shop Customer Queue Barber One Barber with one Customer Queue

The queue could be empty Before Opening Barber The queue could be empty

Barber goes to sleep if the Barber shop opens with an empty queue

There may be customers waiting in the queue Before Opening C1 C2 C3 Barber There may be customers waiting in the queue

Barber Shop Opens Barber removes customer from the queue Barber Barber wakes up customer after the hair cut

Barber Shop is Open C2 C3 C3 Barber C2 C1

Barber Shop is Open C3 Barber C3 C2

Barber goes to sleep when the queue is empty Barber Shop is Open Barber Barber goes to sleep when the queue is empty

New Customer Comes when the Barber is Sleeping Customer enters queue, wakes up barber, Then goes to sleep. Barber

New Customer Comes when the Barber is Sleeping Barber will remove customer from the queue. Barber C4

New Customer Comes C5 C6 Barber C4

Barber should finish all waiting customers Barber Shop Closing C5 C6 Barber should finish all waiting customers Barber C4

New customers don’t wait when shop is closing Barber Shop Closing C7 C5 C6 New customers don’t wait when shop is closing Barber C4

New customers don’t wait when shop is closing Barber Shop Closing C8 C6 New customers don’t wait when shop is closing Barber C5

New customers don’t wait when shop is closing Barber Shop Closing C9 New customers don’t wait when shop is closing Barber C6

Barber shop can open again Barber Shop Closed Barber shop can open again Barber

New customers wait when shop is closed Barber Shop Closed C10 C11 New customers wait when shop is closed Barber

Barber Shop Opens Barber removes customer from the queue Barber Barber wakes up customer after the hair cut

Closing Before Exiting Barber C11

Closing Before Exiting Asking user Yes/No Barber

Customers come and wait User No C1 C2 C3 Customers come and wait Barber

Exiting Before Opening C1 C2 C3 Clear customer queue Barber

Barber Thread Creating a new thread when the Barber shop opens The thread will be terminated when the Shop closed When the Shop opens again, a new thread is created The run sub of the Barber class is for one iteration of Open-Close to make code simpler

Prog5 ‘ Waits for all readers and writers to finish the work in order to ‘ terminate the program. ‘ Mutual exclusion on the DataObj and the queue must be enforced. Public Shared Sub FinishReadWrite() _database.LockDataObj() Monitor.Enter(FIFOQueue) If FIFOQueue.Count > 0 or _database.TheDatabaseStatus <> DataBaseClass.DatabaseStatus.Empty Then endProgram.Reset() Else endProgram.Set() End If Monitor.Exit(FIFOQueue) _database.ReleaseDataObj() endProgram.WaitOne() ‘do not know which thread will wake it up End Sub

JOIN Method Public Sub CloseBarberShop() Monitor.Enter(BarberShopClass.TheBarberStateObj) BarberShopClass.theBarberState = BarberShopClass.BarberState.Closing Monitor.Exit(BarberShopClass.TheBarberStateObj) barberEvent.Set() ‘ Wait until _barberThread is terminated _barberThread.Join() End Sub