CSE 451 Section 1/27/2000.

Slides:



Advertisements
Similar presentations
Operating Systems Semaphores II
Advertisements

Operating Systems Part III: Process Management (Process Synchronization)
Concurrency: Deadlock and Starvation Chapter 6. Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate.
CAS3SH3 Midterm Review. The midterm 50 min, Friday, Feb 27 th Materials through CPU scheduling closed book, closed note Types of questions: True & False,
Ch 7 B.
Resource management and Synchronization Akos Ledeczi EECE 354, Fall 2010 Vanderbilt University.
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
Chapter 6: Process Synchronization
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
CH7 discussion-review Mahmoud Alhabbash. Q1 What is a Race Condition? How could we prevent that? – Race condition is the situation where several processes.
Operating Systems CMPSC 473 Mutual Exclusion Lecture 13: October 12, 2010 Instructor: Bhuvan Urgaonkar.
Threading Part 4 CS221 – 4/27/09. The Final Date: 5/7 Time: 6pm Duration: 1hr 50mins Location: EPS 103 Bring: 1 sheet of paper, filled both sides with.
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.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.
Semaphores CSCI 444/544 Operating Systems Fall 2008.
1 Concurrency: Deadlock and Starvation Chapter 6.
Race Conditions CS550 Operating Systems. Review So far, we have discussed Processes and Threads and talked about multithreading and MPI processes by example.
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Process Synchronization.
Computer Science 162 Discussion Section Week 3. Agenda Project 1 released! Locks, Semaphores, and condition variables Producer-consumer – Example (locks,
Synchronization CSCI 444/544 Operating Systems Fall 2008.
Semaphores. Readings r Silbershatz: Chapter 6 Mutual Exclusion in Critical Sections.
Nachos Phase 1 Code -Hints and Comments
Object Oriented Analysis & Design SDL Threads. Contents 2  Processes  Thread Concepts  Creating threads  Critical sections  Synchronizing threads.
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.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Mutual Exclusion.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization.
Kernel Locking Techniques by Robert Love presented by Scott Price.
Monitors and Blocking Synchronization Dalia Cohn Alperovich Based on “The Art of Multiprocessor Programming” by Herlihy & Shavit, chapter 8.
1 Condition Variables CS 241 Prof. Brighten Godfrey March 16, 2012 University of Illinois.
CSE 451: Operating Systems Section 5 Synchronization.
CS 153 Design of Operating Systems Winter 2016 Lecture 7: Synchronization.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 5: Process Synchronization.
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
6.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles 6.5 Semaphore Less complicated than the hardware-based solutions Semaphore S – integer.
CSE 451 Section #3. Questions from Lecture Kinds of threads When threads are used How threads are implemented Scheduling.
Deadlock and Starvation
CPS 310 midterm exam #1, 2/19/2016 Your name please: ___________________ NetID:___________ /40 /40 /50.
Process Synchronization: Semaphores
Auburn University COMP 3500 Introduction to Operating Systems Synchronization: Part 4 Classical Synchronization Problems.
Background on the need for Synchronization
Deadlock and Starvation
Outline Other synchronization primitives
Other Important Synchronization Primitives
Chapter 5: Process Synchronization
CSE451 Basic Synchronization Spring 2001
HW1 and Synchronization & Queuing
Lecture 13: Producer-Consumer and Semaphores
The Active Object Pattern
Synchronization Issues
COP 4600 Operating Systems Fall 2010
Midterm review: closed book multiple choice chapters 1 to 9
Semaphore Originally called P() and V() wait (S) { while S <= 0
Synchronization Hank Levy 1.
Lecture 2 Part 2 Process Synchronization
Chapter 7: Synchronization Examples
CSE 451 Autumn 2003 Section 3 October 16.
February 5, 2004 Adrienne Noble
Lecture 13: Producer-Consumer and Semaphores
CSE 451: Operating Systems Autumn 2003 Lecture 7 Synchronization
CSE 451: Operating Systems Autumn 2005 Lecture 7 Synchronization
Synchronization Hank Levy 1.
CSE 451: Operating Systems Winter 2003 Lecture 7 Synchronization
CSE 153 Design of Operating Systems Winter 19
CSE 153 Design of Operating Systems Winter 2019
Monitors and Inter-Process Communication
CSE 542: Operating Systems
CSE 542: Operating Systems
Threads CSE 2431: Introduction to Operating Systems
Presentation transcript:

CSE 451 Section 1/27/2000

Agenda Homework Questions Project Questions Synchronization Examples

Homework Questions 4.4: need to consider both user & kernel threads Need to balance protection vs. performance (e.g. web server) 4.5: When creating a process, need to consider other per-process resources open file table, heap, page table 4.6: need to be clearer about how an address space is switched Pointer to current address space changed

Project Questions Assignment 0: many people didn’t list: When interrupts were enabled / disabled When ChildFunction is called When a thread finishes Any questions?

Synchronization Types Semaphore Mutex Monitor Condition variables

Synchronization Examples Linked List Worker Threads Reference Counting

Linked List Have a basic list: How do you synchronize? Struct list_element { Struct list_element * Next, Int Data; } How do you synchronize? How many locks? When do you lock?

Linked List (2) Protect access to list itself: Use mutex, if reading and writing both common Use reader/writer lock of reading more common Protect access to the data of the list Use a mutex per item? Use a mutex for all the data? Signaling events for the list List empty? List full?

Deadlock What if have mutex per list item: What to do? Thread A locks object 1 Thread B locks object 2 Thread A blocks trying to lock object 2 Thread B blocks trying to lock object 1 What to do?

Deadlock Prevention When waiting, see if other thread is waiting for any locks you own. Lock all objects in order, so both threads lock Object 1 then Object 2

Reference Counting Pool of data structures used by several threads Periodically, new ones are added, existing ones deleted May be in use when deleted

Reference Counting (2) Have a linked list of objects Have a reference count per object One count for being on list One count for being in use When in use by thread, increment reference count When removed from list, decrement reference count & remove from list When count goes to zero, delete.

Bridge Traffic Given a one lane bridge that holds 3 cars, implement: ArriveBridge(direction) – blocks until safe to travel CrossBridge(direction) – crosses bridge ExitBridge(direction) – exits the bridge in the direction Need to ensure: No more than 3 cars on the bridge at once All cars go in the same direction Every once in while the direction switches

Worker Threads Problem: How do you do this? Requests come in Work done by several threads from a pool One thread combines results and returns How do you do this?

Worker Threads (2) Thread Pools – useful if thread creation is expensive (as it is on Windows NT, or with kernel threads) Have high/low water mark for number of threads. Have queue of work items. Is consumer / producer, but consumer must signal the correct thread when done May need to wait for multiple threads

Worker Threads (2) Each work item has a semaphore When client arrives: Worker thread signals when done Client thread initializes to # of tasks, waits on semaphore When client arrives: Checks # of available threads. If #avail < #needed, create one up to MAX_THREADS When thread finishes, if no work item, and #threads > MIN_THREADS, sleep for a while then exit.

Invariants Useful technique Have an invariant that is true when a lock is acquired or signaled E.g. list is non-empty Linked list has no loops Allows for easier verification of code

How do you choose a style? Monitors Good for write contention Small amount of data Short amount of processing time Need signaling / waiting Condition Variables Like monitors, but without language support More flexible semantics

Choosing style(2) Mutexes Reader/Writer locks Good when no waiting is needed, just mutual exclusion There are tools to help find when mutexes aren’t used properly (Eraser) Reader/Writer locks Good when doing mostly reading, but occasionally writing Under heavy use may have starvation problems More expensive for common case than a mutex (24 cycles vs 12 cycles)

Choosing a Style (3) Semaphores Good for complex situations: Multiple accessors at once Waiting for multiple things to happen Good for counting objects E.g. number of threads, elements in a buffer

Choosing What to Synchronize Given a linked list, what do you use? A mutex for the whole list? A mutex for each element? A mutex for a group of elements? (using a hash) More mutexes Higher performance More complexity Fewer Mutexes Lower performance (more unnecessary waiting) Simplified code

Other options Cheat – don’t always synchronize: InitDone = false; … If (!InitDone) { lock(mutex); if (!InitDone) { DoInitialization(); InitDone = true; } release(mutex);

Other Options Lock just some fields of a record Caveat: depending on how fields are laid out, the processor may not be able to access them safely Example: Struct foo { Char a; // no lock needed Char b; // lock needed } foo.a = 3 does this: Ld r1, foo Movb r1, 3 St foo, r1 B may be clobbered.