Lecture 8 Page 1 CS 111 Online Other Important Synchronization Primitives Semaphores Mutexes Monitors.

Slides:



Advertisements
Similar presentations
Operating Systems ECE344 Midterm review Ding Yuan
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.
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community.
Threads, SMP, and Microkernels Chapter 4. Process Resource ownership - process is allocated a virtual address space to hold the process image Scheduling/execution-
Concurrency in Shared Memory Systems Synchronization and Mutual Exclusion.
Computer Systems/Operating Systems - Class 8
Review: Chapters 1 – Chapter 1: OS is a layer between user and hardware to make life easier for user and use hardware efficiently Control program.
Chapter 5 Processes and Threads Copyright © 2008.
Concurrency, Race Conditions, Mutual Exclusion, Semaphores, Monitors, Deadlocks Chapters 2 and 6 Tanenbaum’s Modern OS.
1 CS318 Project #3 Preemptive Kernel. 2 Continuing from Project 2 Project 2 involved: Context Switch Stack Manipulation Saving State Moving between threads,
5.6 Semaphores Semaphores –Software construct that can be used to enforce mutual exclusion –Contains a protected variable Can be accessed only via wait.
Concurrency CS 510: Programming Languages David Walker.
Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.
I/O Hardware n Incredible variety of I/O devices n Common concepts: – Port – connection point to the computer – Bus (daisy chain or shared direct access)
3.5 Interprocess Communication Many operating systems provide mechanisms for interprocess communication (IPC) –Processes must communicate with one another.
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.
3.5 Interprocess Communication
Advanced OS Chapter 3p2 Sections 3.4 / 3.5. Interrupts These enable software to respond to signals from hardware. The set of instructions to be executed.
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
1 Concurrency: Deadlock and Starvation Chapter 6.
© 2004, D. J. Foreman 2-1 Concurrency, Processes and Threads.
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
Chapter 8 Windows Outline Programming Windows 2000 System structure Processes and threads in Windows 2000 Memory management The Windows 2000 file.
Chapter 4 Threads, SMP, and Microkernels Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E.
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago Polytechnic,
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 2: System Structures.
I/O Systems I/O Hardware Application I/O Interface
CS 153 Design of Operating Systems Spring 2015 Lecture 11: Scheduling & Deadlock.
Cosc 4740 Chapter 6, Part 3 Process Synchronization.
Processes and Threads Processes have two characteristics: – Resource ownership - process includes a virtual address space to hold the process image – Scheduling/execution.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
CE Operating Systems Lecture 11 Windows – Object manager and process management.
4061 Session 23 (4/10). Today Reader/Writer Locks and Semaphores Lock Files.
Games Development 2 Concurrent Programming CO3301 Week 9.
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 CSE 411 Multi-processor Operating Systems Multi-processor Operating Systems Dec Lecture 30 Instructor: Bhuvan Urgaonkar.
1 Threads, SMP, and Microkernels Chapter 4. 2 Process Resource ownership: process includes a virtual address space to hold the process image (fig 3.16)
CSE 451: Operating Systems Section 5 Midterm review.
Discussion Week 2 TA: Kyle Dewey. Overview Concurrency Process level Thread level MIPS - switch.s Project #1.
Lecture 8 Page 1 CS 111 Fall 2015 Synchronization, Critical Sections and Concurrency CS 111 Operating Systems Peter Reiher.
Department of Computer Science and Software Engineering
CS399 New Beginnings Jonathan Walpole. 2 Concurrent Programming & Synchronization Primitives.
CSE 451: Operating Systems Section 5 Synchronization.
13-1 Chapter 13 Concurrency Topics Introduction Introduction to Subprogram-Level Concurrency Semaphores Monitors Message Passing Java Threads C# Threads.
CSE 153 Design of Operating Systems Winter 2015 Midterm Review.
Lecture 12 Page 1 CS 111 Online Using Devices and Their Drivers Practical use issues Achieving good performance in driver use.
Lecture 6 Page 1 CS 111 Summer 2013 Concurrency Solutions and Deadlock CS 111 Operating Systems Peter Reiher.
Lecture 8 Page 1 CS 111 Winter 2014 Synchronization, Critical Sections and Concurrency CS 111 Operating Systems Peter Reiher.
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 2: The Linux System Part 3.
Chapter 4 Threads, SMP, and Microkernels Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E.
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
Threads, SMP, and Microkernels Chapter 4. Processes and Threads Operating systems use processes for two purposes - Resource allocation and resource ownership.
Module 12: I/O Systems I/O hardware Application I/O Interface
Outline Other synchronization primitives
Other Important Synchronization Primitives
INTER-PROCESS COMMUNICATION
CSCI 315 Operating Systems Design
I/O Systems I/O Hardware Application I/O Interface
Operating System Concepts
CS703 - Advanced Operating Systems
Chapter 2: The Linux System Part 3
Threading And Parallel Programming Constructs
Lecture 4- Threads, SMP, and Microkernels
Concurrency: Mutual Exclusion and Process Synchronization
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
CS333 Intro to Operating Systems
CSE 153 Design of Operating Systems Winter 2019
CSE 542: Operating Systems
Chapter 3: Process Management
Presentation transcript:

Lecture 8 Page 1 CS 111 Online Other Important Synchronization Primitives Semaphores Mutexes Monitors

Lecture 8 Page 2 CS 111 Online Semaphores Counters for sequence coord. and mutual exclusion Can be binary counters or more general – E.g., if you have multiple copies of the resource Call wait() on the semaphore to obtain exclusive access to a critical section – For binary semaphores, you wait till whoever had it signals they are done Call signal() when you’re done For sequence coordination, signal on a shared semaphore when you finish first step – Wait before you do second step

Lecture 8 Page 3 CS 111 Online Mutexes A synchronization construct to serialize access to a critical section Typically implemented using semaphores Mutexes are one per critical section – Unlike semaphores, which protect multiple copies of a resource

Lecture 8 Page 4 CS 111 Online Monitors An object oriented synchronization primitive – Sort of very OO mutexes – Exclusion requirements depend on object/methods – Implementation should be encapsulated in object – Clients shouldn't need to know the exclusion rules A monitor is not merely a lock – It is an object class, with instances, state, and methods – All object methods protected by a semaphore Monitors have some very nice properties – Easy to use for clients, hides unnecessary details – High confidence of adequate protection

Lecture 8 Page 5 CS 111 Online Synchronization in Real World Operating Systems How is this kind of synchronization handled in typical modern operating systems? In the kernel itself? In user-level OS features?

Lecture 8 Page 6 CS 111 Online Kernel Mode Synchronization Performance is a major concern – Many different types of exclusion are available Shared/exclusive, interrupt-safe, SMP-safe Choose type best suited to the resource and situation – Implementations are in machine language Carefully coded for optimum performance Extensive use of atomic instructions Imposes a greater burden on the callers – Most locking is explicit and advisory – Caller expected to know and follow locking rules

Lecture 8 Page 7 CS 111 Online User Mode Synchronization Simplicity and ease of use of great importance – Conservative, enforced, one-size-fits-all locking E.g., exclusive use, block until available – Implicitly associated with protected system objects E.g., files, processes, message queues, events, etc. System calls automatically serialize all operations Explicit serialization is only rarely used – To protect shared resources in multi-threaded apps – Simpler behavior than kernel-mode – Typically implemented via system calls into the OS

Lecture 8 Page 8 CS 111 Online Why Require System Calls for User Level Sync Operations? Mutual exclusion operations likely involve the blocking and unblocking of threads – These are controlled by the operating system Critical sections in the implementations of those operations must be protected – From interrupts or SMP parallelism The OS already has powerful serialization mechanisms – It is easier to build on top of these

Lecture 8 Page 9 CS 111 Online Why Is Performance More Important for Kernel Sync? Multi-threaded execution in user mode is rare – High resource contention even rarer – So performance problems with user-mode serialization are extremely rare The OS, on the other hand, is always running multiple concurrent threads The OS also includes many high use resources Avoiding resource contention is key to achieving good multi-processor scalability

Lecture 8 Page 10 CS 111 Online So Why Provide Multiple Sync Primitives? If performance (and correctness) is so vital in OS sync, why not do it once? – Quick and right Multiple types of locking operation lead to better performance – Least restrictive locking discipline (e.g. reader/writer locks) can greatly reduce resource contention – Choosing exactly when and which locks are obtained and released can minimize the time spent in the critical section – Lessening the danger of deadlocks

Lecture 8 Page 11 CS 111 Online Case Study: Unix Synchronization Internal use is very specific to particular Unix implementation – Linux makes extensive use of semaphores internally But all Unix systems provide some user-level synchronization primitives – Including Linux

Lecture 8 Page 12 CS 111 Online Unix User Synchronization Mechanisms Semaphores – Mostly supporting a Posix standard interface – sem_open, sem_close, sem_post, sem_wait Mutual exclusion file creation (O_EXCL) Advisory file locking (flock) – Shared/exclusive, blocking/non-blocking Enforced record locking (lockf) – Locks a contiguous region of a file – Lock/unlock/test, blocking/non-blocking All blocks can be aborted by a timer

Lecture 8 Page 13 CS 111 Online Unix Asynchronous Completions Most events are associated with open files – Normal files and devices – Network or inter-process communication ports Users can specify blocking or non-blocking use – Non-blocking returns if no data is yet available – Poll if a logical channel is ready or would block – Select the first of n channels to become ready Users can also yield and wait – E.g., for the termination of a child process Signal will awaken a process from any blockage – E.g., alarm clock signal after specified time interval

Lecture 8 Page 14 CS 111 Online Completion Events Available in Linux and other Unix systems Used in multithreaded programs One thread creates and starts a completion Another thread calls a routine to wait on that completion event The thread that completes it makes another call – Which results in the waiting thread being woken

Lecture 8 Page 15 CS 111 Online Case Study: Windows Synchronization Windows includes many synchronization methods – File locking – Other synchronization primitives

Lecture 8 Page 16 CS 111 Online Windows File Locking By default, Windows applications have exclusive access to files they open – Can allow sharing For shared files, byte range locking provided – Applications can specify ranges of bytes in the file to lock Shared or exclusive locking – Windows file systems treat locks as mandatory – Other applications using file mapping treat them as advisory

Lecture 8 Page 17 CS 111 Online Other Windows Synchronization Primitives A wide range – Mutexes (of several kinds) – Critical regions (and guarded regions, which are less protected) – Event-based synchronization E.g., waiting for an event to complete – Semaphores – Spin locks (several kinds) – Timers