Concurrent Processes Lecture 5. Introduction Modern operating systems can handle more than one process at a time System scheduler manages processes and.

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

Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Operating Systems Part III: Process Management (Process Synchronization)
Synchronization and Deadlocks
1 Chapter 5 Concurrency: Mutual Exclusion and Synchronization Principals of Concurrency Mutual Exclusion: Hardware Support Semaphores Readers/Writers Problem.
Lecture 6 :Deadlocks. Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate with each other Involves.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Concurrent Programming Problems OS Spring Concurrency pros and cons Concurrency is good for users –One of the reasons for multiprogramming Working.
Chapter 2 Processes and Threads
Chapter 6: Process Synchronization
5.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 5: CPU Scheduling.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
Process Synchronization. Module 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores.
Operating System Concepts and Techniques Lecture 12 Interprocess communication-1 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and.
Mutual Exclusion.
Interprocess Communication
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Concurrency.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
EEE 435 Principles of Operating Systems Interprocess Communication Pt I (Modern Operating Systems 2.3)
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Avishai Wool lecture Introduction to Systems Programming Lecture 4 Inter-Process / Inter-Thread Communication.
Avishai Wool lecture Priority Scheduling Idea: Jobs are assigned priorities. Always, the job with the highest priority runs. Note: All scheduling.
OS Spring 2004 Concurrency: Principles of Deadlock Operating Systems Spring 2004.
CMPT 300: Operating Systems Review THIS REIVEW SHOULD NOT BE USED AS PREDICTORS OF THE ACTUAL QUESTIONS APPEARING ON THE FINAL EXAM.
Concurrency: Mutual Exclusion, Synchronization, Deadlock, and Starvation in Representative Operating Systems.
OS Fall’02 Concurrency: Principles of Deadlock Operating Systems Fall 2002.
Chapter 2.3 : Interprocess Communication
Chapter 11 Operating Systems
1 Interprocess Communication Race Conditions Two processes want to access shared memory at same time.
OPERATING SYSTEMS DESIGN AND IMPLEMENTATION Third Edition ANDREW S. TANENBAUM ALBERT S. WOODHULL Yan hao (Wilson) Wu University of the Western.
Concurrency, Mutual Exclusion and Synchronization.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Introduction to Concurrency.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Mutual Exclusion.
1 Chapter 2.3 : Interprocess Communication Process concept  Process concept  Process scheduling  Process scheduling  Interprocess communication Interprocess.
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.
Chapter 7 -1 CHAPTER 7 PROCESS SYNCHRONIZATION CGS Operating System Concepts UCF, Spring 2004.
CY2003 Computer Systems Lecture 04 Interprocess Communication.
15.1 Threads and Multi- threading Understanding threads and multi-threading In general, modern computers perform one task at a time It is often.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Background Concurrent access to shared data may result in data inconsistency Maintaining data consistency requires mechanisms to ensure the orderly execution.
CS399 New Beginnings Jonathan Walpole. 2 Concurrent Programming & Synchronization Primitives.
Deadlock Operating Systems: Internals and Design Principles.
Copyright © Curt Hill Concurrent Execution An Overview for Database.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
C H A P T E R E L E V E N Concurrent Programming Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
CGS 3763 Operating Systems Concepts Spring 2013 Dan C. Marinescu Office: HEC 304 Office hours: M-Wd 11: :30 AM.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
1 Processes and Threads Part II Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
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.
Interprocess Communication Race Conditions
Background on the need for Synchronization
G.Anuradha Reference: William Stallings
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Concurrency: Mutual Exclusion and Synchronization
Chapter 7: Deadlocks.
Lecture 2 Part 2 Process Synchronization
Concurrency.
Concurrency: Mutual Exclusion and Process Synchronization
CS333 Intro to Operating Systems
Chapter 6: Synchronization Tools
Chapter 3: Process Management
Presentation transcript:

Concurrent Processes Lecture 5

Introduction Modern operating systems can handle more than one process at a time System scheduler manages processes and their competition for the CPU Memory manager role is to manage sharing of main memory between active processes Look at how processes coexist and communicate with each other on modern computer

Concurrency pros and cons Concurrency is good for users –One of the reasons for multiprogramming Working on the same problem, simultaneous execution of programs, background execution Concurrency is a “pain in the neck” for the system –Access to shared data structures –Deadlock due to resource contention –Enabling process interaction

Concepts: A process is a program in execution. A process has state, including resources like memory and open files, as well as the contents of its program counter. This is the process’s execution context. A concurrent program has more than one execution context. This type of program is also referred to as a multi-threaded program. A parallel program is a concurrent program with more than one thread executing simultaneously.

Relationships between processes Fully indenendant – separate applications running on the one system Indenpendant but related – example users running their own copy of a data entry program but accessing and updating the one database Concurrent processes – set of cooperating processes, example C program

Resources Processes compete for CPU, memory, I/O devices, secondary storage Other resources may include data items in main memory such as message queues, shared data structures. Resources can be reusable or consumable, reusable examples are CPU, main memory (serial reusable example is printer). Consumable resource is created by one process and consumed by another example is message sent between one process and another.

Mutual Exclusive It is necessary for some resources to remain allocated to a process for as long as process requires. Serial reusable resources require mutual exclusion. Example printer is being used by a process then it must remain allocated to the process until printout is complete. Mutual exclusion gives rise to another problem which OS must handle – deadlock.

Deadlock Deadlock is where a process is waiting for an event that will never occur. Example Process P1 has a printer allocated and is attempting to open a file F. Process P2 has already obtained exclusive access to file F and now requests printer. Each process is waiting for a resource held by the other, while holding a resource required by the other.

Mutual Exclusion First Attempt Busy Waiting –Process is always checking to see if it can enter the critical section –Process can do nothing productive until it gets permission to enter its critical section

Co-routine Designed to be able to pass execution control back and forth between themselves Inadequate to support concurrent processing

Second Attempt Each process can examine the other’s status but cannot alter it When a process wants to enter the critical section is checks the other processes first If no other process is in the critical section, it sets its status for the critical section This method does not guarantee mutual exclusion Each process can check the flags and then proceed to enter the critical section at the same time

Third Attempt Set flag to enter critical section before check other processes If another process is in the critical section when the flag is set, the process is blocked until the other process releases the critical section Deadlock is possible when two process set their flags to enter the critical section. Now each process must wait for the other process to release the critical section

Fourth Attempt A process sets its flag to indicate its desire to enter its critical section but is prepared to reset the flag Other processes are checked. If they are in the critical region, the flag is reset and later set to indicate desire to enter the critical region. This is repeated until the process can enter the critical region

Fourth Attempt (contd.) It is possible for each process to set their flag, check other processes, and reset their flags. This scenario will not last very long so it is not deadlock. It is undesirable

Correct Solution Each process gets a turn at the critical section If a process wants the critical section, it sets its flag and may have to wait for its turn

Critical region The area of a process which is sensitive to inter-process complications is called the critical region. To guarantee mutual exclusion only one process is allowed to enter its critical region at a time. OS need a system to ensure process cannot enter critial region if another process is in it’s. (semaphores)

Mutual Exclusion with Busy Waiting Figure 2-9 Mutual exclusion using critical regions.

Critical Regions (1) Four conditions to provide mutual exclusion 1. No two processes simultaneously in critical region 2. No assumptions made about speeds or numbers of CPUs 3. No process running outside its critical region may block another process 4. No process must wait forever to enter its critical region

Semaphores: What are they? Semaphore is a system of communication using flags. There are 2 stations a sender and reciever and they must be able to clearly see the other station. For long distance communication, there could be a number of repeater stations between the sender and reciever. Generally a station comprises of 2 people.

Semaphores: In Software (contd.) Dijkstra in 1965 proposed semaphores as a solution to the problems of concurrent processes. The fundamental principle is: That two or more processes can cooperate by means of simple signals, such that a process can be forced to stop at a specified place until it has received a specific signal. For signaling, special variables called semaphores are used. –Primitive signal (s) is used to transmit a signal –Primitive wait (s) is used to receive a signal

File and record locking Mutual exclusion is required file processing where several users are accessing the same file (databases) Example airline booking system, one seat left two agents access at same time before file is updated and seat is double booked. Solution is file locking preventing access to the file while it is being updated

Types of file locking File lock – whole file is locked, prevents any other process accessing any part of that file. Write lock – if a specific set of data (eg order file) is write locked prevents other process modifying or reading data Read lock – set of data is read locked other processes may read data but no process can modify it.