Concurrency: Mutual Exclusion, Synchronization, Deadlock, and Starvation in Representative Operating Systems.

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

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.
1 Chapter 5 Concurrency: Mutual Exclusion and Synchronization Principals of Concurrency Mutual Exclusion: Hardware Support Semaphores Readers/Writers Problem.
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community.
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago Polytechnic,
Chapter 6: 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)
Deadlocks, Message Passing Brief refresh from last week Tore Larsen Oct
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles Seventh Edition By William Stallings.
Concurrency: mutual exclusion and synchronization Slides are mainly taken from «Operating Systems: Internals and Design Principles”, 8/E William Stallings.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Chapter 6 Concurrency: Deadlock and Starvation
Concurrency in Shared Memory Systems Synchronization and Mutual Exclusion.
Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 91 Today’s class Mutual exclusion and synchronization 
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Avishai Wool lecture Introduction to Systems Programming Lecture 4 Inter-Process / Inter-Thread Communication.
Concurrency: Deadlock and Starvation Chapter 6. Revision Describe three necessary conditions for deadlock Which condition is the result of the three necessary.
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.
Inter Process Communication:  It is an essential aspect of process management. By allowing processes to communicate with each other: 1.We can synchronize.
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.
Concurrency: Deadlock and Starvation Chapter 6. Goal and approach Deadlock and starvation Underlying principles Solutions? –Prevention –Detection –Avoidance.
1 Concurrency: Deadlock and Starvation Chapter 6.
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago Polytechnic,
CS510 Concurrent Systems Introduction to Concurrency.
Cosc 4740 Chapter 6, Part 3 Process Synchronization.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Introduction to Concurrency.
6.3 Peterson’s Solution The two processes share two variables: Int turn; Boolean flag[2] The variable turn indicates whose turn it is to enter the critical.
4061 Session 23 (4/10). Today Reader/Writer Locks and Semaphores Lock Files.
SOLARIS Andrew Trice Jon Rossman Alex Kozel Gary Greene Jake Cyrus.
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.
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago Polytechnic,
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Lecture 8 Page 1 CS 111 Online Other Important Synchronization Primitives Semaphores Mutexes Monitors.
1 Interprocess Communication (IPC) - Outline Problem: Race condition Solution: Mutual exclusion –Disabling interrupts; –Lock variables; –Strict alternation.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Operating System Chapter 6. Concurrency: Deadlock and Starvation Lynn Choi School of Electrical Engineering.
CS399 New Beginnings Jonathan Walpole. 2 Concurrent Programming & Synchronization Primitives.
Monitors and Blocking Synchronization Dalia Cohn Alperovich Based on “The Art of Multiprocessor Programming” by Herlihy & Shavit, chapter 8.
CSE 153 Design of Operating Systems Winter 2015 Midterm Review.
Concurrency in Shared Memory Systems Synchronization and Mutual Exclusion.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
CS510 Concurrent Systems Jonathan Walpole. Introduction to Concurrency.
© 2004, D. J. Foreman 1 Monitors and Inter-Process Communication.
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.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Interprocess Communication Race Conditions
Operating systems Deadlocks.
Outline Other synchronization primitives
Other Important Synchronization Primitives
Concurrency: Mutual Exclusion and Synchronization
Threading And Parallel Programming Constructs
Operating systems Deadlocks.
Concurrency: Mutual Exclusion and Process Synchronization
Chapter 6 Synchronization Principles
CSE 153 Design of Operating Systems Winter 19
Chapter 6: Synchronization Tools
Monitors and Inter-Process Communication
CSE 542: Operating Systems
CSE 542: Operating Systems
Presentation transcript:

Concurrency: Mutual Exclusion, Synchronization, Deadlock, and Starvation in Representative Operating Systems

CS-550: Concurrency in Representative Operating Systems Mutual exclusion Semaphores Monitors Message passing Deadlock Deadlock prevention Deadlock avoidance Deadlock detection Starvation CS-550: Concurrency in Representative Operating Systems

UNIX Concurrency Mechanisms Mechanisms for interprocess communication and synchronization: Pipes Messages Shared memory Semaphores Signals Pipes, messages, and shared memory are used to communicate between processes, semaphores and signals to trigger actions by other processes CS-550: Concurrency in Representative Operating Systems

UNIX Concurrency Mechanisms (cont.) Pipes Major contribution to the development of OSs Circular buffer allowing two processes to communicate using a producer-consumer model FIFO queue, written by one process and read by another Pipe created with fixed number of bytes Write If room available, executed immediately Else, process is blocked Read If requested number of bytes available, executed immediately Else, process blocked Mutual exclusion enforced by the OS: one process at a time can access pipe Pipe types: Named: shared by unrelated processes Unnamed: shared by related processes CS-550: Concurrency in Representative Operating Systems

UNIX Concurrency Mechanisms (cont.) Messages Block of text with accompanying type Operation System calls: msgsnd and msgrcv Each process has message queue – mailbox Message sender specifies type of message Message receiver can retrieve messages by type or FIFO Synchronization Message sender suspended if tries to send to a full queue Message receiver suspended if tries to read from an empty queue Message receiver not suspended if attempts to read a message of certain type and no message present CS-550: Concurrency in Representative Operating Systems

UNIX Concurrency Mechanisms (cont.) Shared memory Fastest method of interprocess communication in UNIX Common block of virtual memory shared by several processes Operation: same read/write operations as the rest of the virtual memory Protection: per-process, read-only or read-write Synchronization must be provided by processes using shared memory CS-550: Concurrency in Representative Operating Systems

UNIX Concurrency Mechanisms (cont.) Semaphores Generalization of the semaphore concept Kernel implements semaphore operations atomically: no other process can access the semaphore until all operations are done Semaphore elements Current value of semaphore Process ID of last process to operate on the semaphore Number of processes waiting for the semaphore value to be greater than current value Number of processes waiting for the semaphore value to be zero Each semaphore has associated queues of processes waiting on that semaphore Semaphores created in sets of one or more semaphores CS-550: Concurrency in Representative Operating Systems

UNIX Concurrency Mechanisms (cont.) Signals Software mechanism to inform a process of the occurrence of an asynchronous event A signal can be send process-to-process or internal to kernel Operation: Signal is delivered by updating a field in the process table of the destination process Signal is processed after process wakes up to run or when it returns from a system call Process responds to signal by performing a default action, executing a signal handler function, or ignoring the signal Signals have no priorities and no queuing Signals that occur at the same time are given to process one at a time, without implied ordering Signals of a given type cannot be queued: single bit for each type CS-550: Concurrency in Representative Operating Systems

Solaris Thread Synchronization Primitives Solaris implements four thread synchronization primitives, in addition to the concurrency mechanisms of UNIX SVR4 (in the kernel for kernel threads and in the threads library for user-level threads Mutual exclusion (mutex) locks Semaphores Multiple readers, single writer (reader/writer) locks Condition variables Operation Thread executes a primitive and creates a synchronization object (data structure with requested parameters) Synchronization operations: enter (acquire, lock) and release (unlock) It is the thread’s responsibility to use synchronization primitives properly: there is no mechanism in the kernel or the threads library to enforce mutual exclusion or to prevent deadlock All synchronization primitives require a hardware instruction that can test and set an object in one atomic operation CS-550: Concurrency in Representative Operating Systems

Solaris Thread Synchronization Primitives CS-550: Concurrency in Representative Operating Systems

Solaris Thread Synchronization Primitives CS-550: Concurrency in Representative Operating Systems

Solaris Thread Synchronization Primitives (cont.) Mutual exclusion lock Principle: prevents more than one thread to proceed in a critical section Primitives: mutex-enter(): Acquires the lock, potentially blocking Thread attempts to acquire a mutex lock If lock already set by another thread, blocking action depends on type-specific information stored in the mutex object (spin lock or go on queue of threads sleeping on this lock) Mutex-exit(): Releases the lock, potentially unblocking a waiter Mutex_tryenter(): Acquires the lock if it is not already held Programmer uses a busy-wait for user-level threads, which avoids blocking the entire process because one thread is blocked CS-550: Concurrency in Representative Operating Systems

Solaris Thread Synchronization Primitives (cont.) Semaphores Classic counting semaphores, with following primitives sema_p () Decrements semaphore, potentially blocking thread sema_v () Increments semaphore, potentially unblocking waiting thread Sema_tryp () Decrements semaphore if blocking not required (permits busy waiting) CS-550: Concurrency in Representative Operating Systems

Solaris Thread Synchronization Primitives (cont.) Readers/Writer Lock Operation Either multiple simultaneous read-only threads have access to the protected object (status read lock), or Single write-only thread has access to object for writing, excluding all readers (status write lock) Primitives rw_enter () Attempts to acquire lock as reader or writer rw_exit () Releases a lock as reader or writer rw_tryenter () Acquire the lock if blocking is not required rw_downgrade () An acquired write lock is converted to a read lock. If waiting writer, it waits until lock is released. If no waiting writer, pending readers are awaken rw_tryupgrade () Attempts to convert a reader lock into a writer lock CS-550: Concurrency in Representative Operating Systems

Solaris Thread Synchronization Primitives (cont.) Condition variables Objective: implement a monitor using a condition variable and a mutex lock The condition variable is used to wait until a particular condition is true Primitives cv_wait ( ) Blocks until the condition is signaled; must release associated mutex before blocking and reacquire it before returning cv_signal ( ) Wakes up one of the threads blocked in cv_wait ( ) cv_broadcast ( ) Wakes up all the threads blocked in cv_wait ( ) CS-550: Concurrency in Representative Operating Systems

Windows 2000 Concurrency Mechanisms Synchronization of threads is based on the object architecture The Executive implements synchronization using the synchronization objects The following object types have specific uses, but can be used for synchronization as well Process Thread File Console input The following object types are exclusively designed for synchronization File change notification Mutex Semaphore Event Waitable timer CS-550: Concurrency in Representative Operating Systems

Windows 2000 Concurrency Mechanisms (cont) Operation Each synchronization object instance can be in one of two states: signaled or unsignaled When a thread issues a wait request to the Executive, it uses the handle of the synchronization object If object is in unsignaled state, thread is suspended When object enters the signaled state, Executive releases the thread (and all thread objects waiting on that synchronization object) Objects used exclusively for synchronization File change notification A notification of any file system changes Signaled when change occurs in the file system that matches filter criteria of this object When signaled, one waiting thread is released CS-550: Concurrency in Representative Operating Systems

Windows 2000 Concurrency Mechanisms (cont) Objects used exclusively for synchronization (cont.) Mutex Used to enforce mutually exclusive access to a resource, allowing only one thread at a time to gain access (binary semaphore). Can be used to synchronize threads running on different processes. Used for the Win32 and OS/2 environments. Signaled when owning thread or other thread releases mutex When signaled, only one waiting thread is released Semaphore Counter that regulates the number of threads that can use a resource Signaled when semaphore count drops to zero When signaled, all waiting threads are released. CS-550: Concurrency in Representative Operating Systems

Windows 2000 Concurrency Mechanisms (cont) Objects used exclusively for synchronization (cont.) Event An announcement that a system event has occurred Signaled when thread sets event When signaled, all waiting threads are released Waiting Timer Counter that records the passage of time Signaled when set time arrives or time interval expires CS-550: Concurrency in Representative Operating Systems