Chapter 5 Concurrency: Mutual Exclusion. and. Synchronization. Operating Systems: Internals. and. Design Principles

Similar documents
Chapter 5 Concurrency: Mutual Exclusion and Synchronization

IT 540 Operating Systems ECE519 Advanced Operating Systems

Concurrency: mutual exclusion and synchronization

Concurrency, Mutual Exclusion and Synchronization C H A P T E R 5

Concurrency. Chapter 5

Chapter 5 Asynchronous Concurrent Execution

Lecture 6. Process Synchronization

Lecture Topics. Announcements. Today: Concurrency (Stallings, chapter , 5.7) Next: Exam #1. Self-Study Exercise #5. Project #3 (due 9/28)

Chapter 6 Concurrency: Deadlock and Starvation

Chapters 5 and 6 Concurrency

Concurrency(I) Chapter 5

The concept of concurrency is fundamental to all these areas.

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy

CONCURRENCY:MUTUAL EXCLUSION AND SYNCHRONIZATION

Dealing with Issues for Interprocess Communication

Process Management And Synchronization

Deadlock. Concurrency: Deadlock and Starvation. Reusable Resources

Operating Systems: William Stallings. Starvation. Patricia Roy Manatee Community College, Venice, FL 2008, Prentice Hall

CSc33200: Operating Systems, CS-CCNY, Fall 2003 Jinzhong Niu December 10, Review

Mutual Exclusion and Synchronization

Concurrency: Mutual Exclusion and Synchronization. Concurrency

Process Synchronization

Dr. D. M. Akbar Hussain DE5 Department of Electronic Systems

Lecture Topics. Announcements. Today: Concurrency: Mutual Exclusion (Stallings, chapter , 5.7)

Concurrent Processes Rab Nawaz Jadoon

Concept of a process

Process Synchronization

Chapter 6: Synchronization. Operating System Concepts 8 th Edition,

Module 6: Process Synchronization. Operating System Concepts with Java 8 th Edition

Subject: Operating System (BTCOC403) Class: S.Y.B.Tech. (Computer Engineering)

Process Synchronization. CISC3595, Spring 2015 Dr. Zhang

Chapter 2 Processes and Threads. Interprocess Communication Race Conditions

Threads. Threads The Thread Model (1) CSCE 351: Operating System Kernels Witawas Srisa-an Chapter 4-5

Concurrency: Deadlock and Starvation

IV. Process Synchronisation

Operating Systems. Lecture 4 - Concurrency and Synchronization. Master of Computer Science PUF - Hồ Chí Minh 2016/2017

Process Synchronization: Semaphores. CSSE 332 Operating Systems Rose-Hulman Institute of Technology

Process Synchronization

Operating Systems. Operating Systems Summer 2017 Sina Meraji U of T

Interprocess Communication By: Kaushik Vaghani

Operating Systems: Internals and Design Principles. Chapter 4 Threads Seventh Edition By William Stallings

CSE Traditional Operating Systems deal with typical system software designed to be:

For use by students enrolled in #71251 CSE430 Fall 2012 at Arizona State University. Do not use if not enrolled.

MS Windows Concurrency Mechanisms Prepared By SUFIAN MUSSQAA AL-MAJMAIE

Process Synchronization

Dept. of CSE, York Univ. 1

Sistemas Operacionais I. Valeria Menezes Bastos

Semaphores. To avoid busy waiting: when a process has to wait, it will be put in a blocked queue of processes waiting for the same event

Semaphores. Semaphores. Semaphore s operations. Semaphores: observations

Chapter 5: Process Synchronization. Operating System Concepts Essentials 2 nd Edition

1. Motivation (Race Condition)

Chapter 6: Process Synchronization. Module 6: Process Synchronization

Main Points of the Computer Organization and System Software Module

Module 6: Process Synchronization

CS420: Operating Systems. Process Synchronization

Process Synchronization. Mehdi Kargahi School of ECE University of Tehran Spring 2008

Concurrency: Deadlock and Starvation. Chapter 6

Lesson 6: Process Synchronization

Remaining Contemplation Questions

Synchronization Principles

Concurrency: Mutual Exclusion and

Concurrency: Mutual Exclusion and Synchronization

Chapter 6: Process Synchronization

Chapter 7: Process Synchronization!

Maximum CPU utilization obtained with multiprogramming. CPU I/O Burst Cycle Process execution consists of a cycle of CPU execution and I/O wait

Interprocess Communication and Synchronization

Concurrency: a crash course

CS3502 OPERATING SYSTEMS

1 Process Coordination

Chapter 6: Process Synchronization. Operating System Concepts 8 th Edition,

Chapter 6: Process Synchronization

Synchronization I. Jo, Heeseung

What is the Race Condition? And what is its solution? What is a critical section? And what is the critical section problem?

PROCESS SYNCHRONIZATION

CSC501 Operating Systems Principles. Process Synchronization

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of MCA

Process Synchronization

CHAPTER 6: PROCESS SYNCHRONIZATION

Semaphore. Originally called P() and V() wait (S) { while S <= 0 ; // no-op S--; } signal (S) { S++; }

Process Synchronisation (contd.) Operating Systems. Autumn CS4023

Chapter 6: Synchronization. Chapter 6: Synchronization. 6.1 Background. Part Three - Process Coordination. Consumer. Producer. 6.

Chapter 6: Process Synchronization. Operating System Concepts 8 th Edition,

Lecture 8: September 30

Midterm Exam. October 20th, Thursday NSC

CSC 1600: Chapter 6. Synchronizing Threads. Semaphores " Review: Multi-Threaded Processes"

Synchronization. Race Condition. The Critical-Section Problem Solution. The Synchronization Problem. Typical Process P i. Peterson s Solution

Concurrency: Mutual Exclusion and Synchronization - Part 2

CS370 Operating Systems

CSE 451: Operating Systems Winter Lecture 7 Synchronization. Steve Gribble. Synchronization. Threads cooperate in multithreaded programs

Semaphores. May 10, Mutual exclusion with shared variables is difficult (e.g. Dekker s solution).

CS370 Operating Systems

Semaphores. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Multitasking / Multithreading system Supports multiple tasks

G52CON: Concepts of Concurrency

Synchronization for Concurrent Tasks

Ch 9: Control flow. Sequencers. Jumps. Jumps

Chapter 5: Process Synchronization. Operating System Concepts 9 th Edition

Chapter 7: Process Synchronization. Background. Illustration

Chapter 6: Process Synchronization. Operating System Concepts 9 th Edit9on

General Objectives: To understand the process management in operating system. Specific Objectives: At the end of the unit you should be able to:

Transcription:

Operating Systems: Internals and Design Principles Chapter 5 Concurrency: Mutual Exclusion and Synchronization Seventh Edition By William Stallings

Designing correct routines for controlling concurrent activities proved to be one of the most difficult aspects of systems programming. The ad hoc techniques used by programmers of early multiprogramming and real-time systems were always vulnerable to subtle programming errors whose effects could be observed only when certain relatively rare sequences of actions occurred. The errors are particularly difficult to locate, sincethe precise conditions under which they appear are very hard to reproduce. THE COMPUTER SCIENCE AND ENGINEERING RESEARCH STUDY, MIT Press, 1980

Operating System design is concerned with the management of processes and threads: Multiprogramming Multiprocessing Distributed Processing

Concurrency KEY TERMS Table 5.1 Some Key Terms Related to Concurrency

Interleaving and overlapping can be viewed as examples of concurrent processing both present the same problems Uniprocessor the relative speed of execution of processes cannot be predicted depends on activities of other processes the way the OS handles interrupts scheduling policies of the OS

Difficulties of Concurrency Sharing of global resources Difficult for the OS to manage the allocation of resources optimally Difficult to locate programming errors as results are not deterministic and reproducible

Occurs when multiple processes or threads read and write data items The final result depends on the order of execution the loser of the race is the process that updates last and will determine the final value of the variable

Operating System Concerns Design and management issues raised by the existence of concurrency: The OS must: be able to keep track of various processes allocate and de-allocate resources for each active process protect the data and physical resources of each process against interference by other processes ensure that the processes and outputs are independent of the processing speed

Process Interaction

Concurrent processes come into conflict when they are competing for use of the same resource for example: I/O devices, memory, processor time, clock

Figure 5.1 Illustration of Mutual Exclusion

Must be enforced A process that halts must do so without interfering with other processes No deadlock or starvation A process must not be denied access to a critical section when there is no other process using it No assumptions are made about relative process speeds or number of processes A process remains inside its critical section for a finite time only

Special Machine Instructions Compare&Swap Instruction also called a compare and exchange instruction a compare is made between a memory value and a test value if the values are the same a swap occurs carried out atomically

Figure 5.2 Hardware Support for Mutual Exclusion

Exchange Instruction Figure 5.2 Hardware Support for Mutual Exclusion

Applicable to any number of processes on either a single processor or multiple processors sharing main memory Simple and easy to verify It can be used to support multiple critical sections; each critical section can be defined by its own variable

Busy-waiting is employed, thus while a process is waiting for access to a critical section it continues to consume processor time Starvation is possible when a process leaves a critical section and more than one process is waiting Deadlock is possible

1) May be initialized to a nonnegative integer value 2) The semwait operation decrements the value 3) The semsignal operation increments the value

Semaphore Primitives

Binary Semaphore Primitives

A queue is used to hold processes waiting on the semaphore

Producer/Consumer Problem

Buffer Structure

Figure 5.9 An Incorrect Solution to the Infinite-Buffer Producer/Consumer Problem Using Binary Semaphores

Figure 5.10 A Correct Solution to the Infinite-Buffer Producer/Consumer Problem Using Binary Semaphores

Figure 5.13 A Solution to the Bounded-Buffer Producer/Consumer Problem Using Semaphores

Imperative that the semwait and semsignal operations be implemented as atomic primitives Can be implemented in hardware or firmware Software schemes such as Dekker s or Peterson s algorithms can be used Use one of the hardware-supported schemes for mutual exclusion

Programming language construct that provides equivalent functionality to that of semaphores and is easier to control Implemented in a number of programming languages including Concurrent Pascal, Pascal-Plus, Modula-2, Modula-3, and Java Has also been implemented as a program library Software module consisting of one or more procedures, an initialization sequence, and local data

Monitor Characteristics

Achieved by the use of condition variables that are contained within the monitor and accessible only within the monitor Condition variables are operated on by two functions: cwait(c): suspend execution of the calling process on condition c csignal(c): resume execution of some process blocked after a cwait on the same condition

Figure 5.15 Structure of a Monitor

Figure 5.16 A Solution to the Bounded-Buffer Producer/Consumer Problem Using a Monitor

When processes interact with one another two fundamental requirements must be satisfied: Message Passing is one approach to providing both of these functions works with distributed systems and shared memory multiprocessor and uniprocessor systems

Message Passing The actual function is normally provided in the form of a pair of primitives: send (destination, message) receive (source, message) A process sends information in the form of a message to another process designated by a destination A process receives information by executing the receive primitive, indicating the source and the message

Message Passing Table 5.5 Design Characteristics of Message Systems for Interprocess Communication and Synchronization

Both sender and receiver are blocked until the message is delivered Sometimes referred to as a rendezvous Allows for tight synchronization between processes

Schemes for specifying processes in send and receive primitives fall into two categories:

Send primitive includes a specific identifier of the destination process Receive primitive can be handled in one of two ways: require that the process explicitly designate a sending process effective for cooperating concurrent processes implicit addressing source parameter of the receive primitive possesses a value returned when the receive operation has been performed

Message Passing Example Figure 5.21 A Solution to the Bounded-Buffer Producer/Consumer Problem Using Messages

A data area is shared among many processes some processes only read the data area, (readers) and some only write to the data area (writers) Conditions that must be satisfied: 1.any number of readers may simultaneously read the file 2.only one writer at a time may write to the file 3.if a writer is writing to the file, no reader may read it

Readers Have Priority Figure 5.22 A Solution to the Readers/Writers Problem Using Semaphore: Readers Have Priority

Figure 5.23 A Solution to the Readers/Writers Problem Using Semaphore: Writers Have Priority

State of the Process Queues

Message Passing Figure 5.24 A Solution to the Readers/Writers Problem Using Message Passing