UC Santa Barbara Project 2 Discussion Bryce Boe 2011/04/26 and 2011/04/29.

Slides:



Advertisements
Similar presentations
1 Interprocess Communication 1. Ways of passing information 2. Guarded critical activities (e.g. updating shared data) 3. Proper sequencing in case of.
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.
Synchronization with Eventcounts and Sequencers
Operating Systems Part III: Process Management (Process Synchronization)
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.
Ch 7 B.
1 Synchronization 2: semaphores and more… 1 Operating Systems, 2011, Danny Hendler & Amnon Meisels.
CSCC69: Operating Systems
Chapter 6 Process Synchronization Bernard Chen Spring 2007.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 5: Process Synchronization.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
EEE 435 Principles of Operating Systems Interprocess Communication Pt II (Modern Operating Systems 2.3)
Process Synchronization. Module 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores.
CH7 discussion-review Mahmoud Alhabbash. Q1 What is a Race Condition? How could we prevent that? – Race condition is the situation where several processes.
CS 162 Discussion Section Week 3. Who am I? Mosharaf Chowdhury Office 651 Soda 4-5PM.
UC Santa Barbara Project 1 Discussion Bryce Boe 2011/04/12.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
CS170 Discussion – Bryce Boe. Outline Project 4 Overview Midterm Information Midterm questions / project 3 questions.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts Amherst Operating Systems CMPSCI 377 Lecture.
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.
Chapter 6: Process Synchronization. Outline Background Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores Classic Problems.
5.6.2 Thread Synchronization with Semaphores Semaphores can be used to notify other threads that events have occurred –Producer-consumer relationship Producer.
Inter Process Communication:  It is an essential aspect of process management. By allowing processes to communicate with each other: 1.We can synchronize.
Concurrency: Mutual Exclusion, Synchronization, Deadlock, and Starvation in Representative Operating Systems.
Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Process Synchronization (Or The “Joys” of Concurrent.
A. Frank - P. Weisberg Operating Systems Introduction to Cooperating Processes.
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Process Synchronization.
More Classes in C++ Bryce Boe 2012/08/20 CS32, Summer 2012 B.
CS162B: Semaphores (and Shared Memory) Jacob T. Chan.
1 Processes, Threads, Race Conditions & Deadlocks Operating Systems Review.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Classical problems.
Process Synchronization Continued 7.2 Critical-Section Problem 7.3 Synchronization Hardware 7.4 Semaphores.
Operating Systems CMPSC 473 Mutual Exclusion Lecture 14: October 14, 2010 Instructor: Bhuvan Urgaonkar.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Mutual Exclusion.
Nachos Project 4 Lecturer: Hao-Hua Chu TA: Chun-Po Wang (Artoo) Date: 2008/10/25.
Copyright ©: University of Illinois CS 241 Staff1 Threads Systems Concepts.
CSC321 Concurrent Programming: §5 Monitors 1 Section 5 Monitors.
1 Interprocess Communication (IPC) - Outline Problem: Race condition Solution: Mutual exclusion –Disabling interrupts; –Lock variables; –Strict alternation.
Discussion Week 2 TA: Kyle Dewey. Overview Concurrency Process level Thread level MIPS - switch.s Project #1.
Project 3. “System Call and Synchronization” By Dongjin Kim
Slides created by: Professor Ian G. Harris Operating Systems  Allow the processor to perform several tasks at virtually the same time Ex. Web Controlled.
Operating System Concepts and Techniques Lecture 13 Interprocess communication-2 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and.
Process Synchronization. Objectives To introduce the critical-section problem, whose solutions can be used to ensure the consistency of shared data To.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 6: Process Synchronization.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 5: Process Synchronization.
CRITICAL SECTIONS Dijkstra’s Semaphores. Multiprogramming Multiple programs sharing a processor Ex) Your is open and receiving A web browser.
CS3771 Today: Distributed Coordination  Previous class: Distributed File Systems Issues: Naming Strategies: Absolute Names, Mount Points (logical connection.
Process Synchronization. Concurrency Definition: Two or more processes execute concurrently when they execute different activities on different devices.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
1 Section 5 Synchronization primitives (Many slides taken from Winter 2006)
Process Synchronization
Process Synchronization: Semaphores
Project 3. “System Call and Synchronization”
Operating Systems CMPSC 473
Chapter 5: Process Synchronization
Lecture 13: Producer-Consumer and Semaphores
Topic 6 (Textbook - Chapter 5) Process Synchronization
Threading And Parallel Programming Constructs
Lecture 2 Part 2 Process Synchronization
Critical section problem
Concurrency: Mutual Exclusion and Process Synchronization
Lecture 13: Producer-Consumer and Semaphores
Chapter 6: Synchronization Tools
“The Little Book on Semaphores” Allen B. Downey
Synchronization, Part 2 Semaphores
Chapter 6 – Distributed Processing and File Systems
More concurrency issues
Synchronization and liveness
Presentation transcript:

UC Santa Barbara Project 2 Discussion Bryce Boe 2011/04/26 and 2011/04/29

UC Santa Barbara Project 2 Overview Semaphores Semaphore Service in Minix Pizza Synchronization Problem Bryce Boe – CS170 S11

UC Santa Barbara Semaphore What is a semaphore? – “A semaphore is a data structure that is useful for solving a variety of synchronization problems” Downey, The Little Book of Semaphores Types of synchronization problems – Serialization: A must occur before B – Mutual Exclusion: A and B cannot happen concurrently Bryce Boe – CS170 S11

UC Santa Barbara More on Semaphores Like an integer but… – Can be initialized to any value and then restricted to two main operations operations – Incremented -- V(), up() – Decremented – P(), down() Why P and V? – Initials of Dutch words verhogen (increase) and the portmanteau prolaag [probeer te verlagen] (try to reduce) Bryce Boe – CS170 S11

UC Santa Barbara Adding Semaphores to Minix Implemented as a service – Needs tocall sef_startup on initialization – Calls sef_receive_status to retrieve messages – The service requires the appropriate permissions (/etc/system.conf) to send/receive messages from other processes User-level interface needs to construct messages to pass to the service – Use minix_rs_lookup to find the dynamic service endpoint Bryce Boe – CS170 S11

UC Santa Barbara Semaphore Interface int sem_init(int value) – Initializes new semaphore to value and returns the lowest available semaphore number >= 0 int sem_up(int sem_num) – If no one is waiting, increases the semaphore value – otherwise “wakes up” a the oldest waiting process Bryce Boe – CS170 S11

UC Santa Barbara Semaphore Interface cont. int sem_down(int sem_num) – Decreases the semaphore value – If the semaphore value <= 0 “sleep” the requesting process int sem_release(int sem_num) – If no one is waiting, free the semaphore so that it can be re-used – Otherwise return EINUSE error (need to define in errno.h) Bryce Boe – CS170 S11

UC Santa Barbara Error Handling If an invalid value is passed anywhere EINVAL should be returned to the user If any functions return an error, the errno corresponding to that error should be returned – Such as: malloc, minix_rs_lookup Bryce Boe – CS170 S11

UC Santa Barbara Semaphore (Pizza) Challenge 6 grads, 2 ugrads, 2 tables with pizza Only 1 student can eat at a table at a time Student can only enter room if table is available Grads have priority – 1 ugrad is eating and 1 grad comes in, the ugrad must least – 1 grad is eating, no ugrad can enter Bryce Boe – CS170 S11

UC Santa Barbara Semaphore Challenge cont. Write two programs – grad.c – manage the 6 graduate students – ugrad.c – manage the 2 undergraduate students Use semaphores to correctly manage the consumption of pizza Solution cannot cause starvation Explain your solution in pizza.txt Bryce Boe – CS170 S11

UC Santa Barbara Semaphore Challenge Questions How can you dynamically share semaphore numbers between processes? How do you determine how often the students want to eat, and for how long they eat? Bryce Boe – CS170 S11

UC Santa Barbara Suggested Implementation Order Create skeleton server sema Load and unload sema server via – service up /usr/sbin/sema – service down sema Complete sema service Complete semaphore “pizza” challenge Ensure patch builds everything by running “make world” and your service starts up after a reboot Bryce Boe – CS170 S11

UC Santa Barbara Implementation Notes Copy sched service in servers/ to sema Update etc/systems.conf to add sched service (see man systems.conf if needed) Add constants to include/minix/com.h Add appropriate rc file to start semaphore server Under /usr/src – make includes (updates include files) – make libraries (builds and updates libraries) – make etcforce (updates etc files) – make –C servers install (builds all servers) Bryce Boe – CS170 S11

UC Santa Barbara Resources The Little Book of Semaphores – semaphores.pdf semaphores.pdf Driver programming in Minix – rProgramming rProgramming – Similar setup process Bryce Boe – CS170 S11