Dr. Kalpakis CMSC 621, Advanced Operating Systems. Fall 2003 URL: Introduction & Process Synchronization.

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.
1 Chapter 5 Concurrency: Mutual Exclusion and Synchronization Principals of Concurrency Mutual Exclusion: Hardware Support Semaphores Readers/Writers Problem.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Dr. Kalpakis CMSC 621, Advanced Operating Systems. Fall 2003 URL: Distributed System Architectures.
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 ©2013 Operating System Concepts – 9 th Edition Chapter 5: 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.
CH7 discussion-review Mahmoud Alhabbash. Q1 What is a Race Condition? How could we prevent that? – Race condition is the situation where several processes.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
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 
Computer Systems/Operating Systems - Class 8
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.
5.6 Semaphores Semaphores –Software construct that can be used to enforce mutual exclusion –Contains a protected variable Can be accessed only via wait.
OS Fall ’ 02 Introduction Operating Systems Fall 2002.
Chapter 6: Process Synchronization. Outline Background Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores Classic Problems.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 8, 2005 Objectives Understand.
Concurrency: Mutual Exclusion, Synchronization, Deadlock, and Starvation in Representative Operating Systems.
OS Spring’03 Introduction Operating Systems Spring 2003.
Chapter 11: Distributed Processing Parallel programming Principles of parallel programming languages Concurrent execution –Programming constructs –Guarded.
CS533 - Concepts of Operating Systems
Real-Time Kernels and Operating Systems. Operating System: Software that coordinates multiple tasks in processor, including peripheral interfacing Types.
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Process Synchronization.
Intro to OS CUCS Mossé Processes and Threads What is a process? What is a thread? What types? A program has one or more locus of execution. Each execution.
Adopted from and based on Textbook: Operating System Concepts – 8th Edition, by Silberschatz, Galvin and Gagne Updated and Modified by Dr. Abdullah Basuhail,
Operating Systems CSE 411 CPU Management Oct Lecture 13 Instructor: Bhuvan Urgaonkar.
Advanced Synchronization Constructs Related Work: Monitors: An Operating System Structuring, C.A.R Hoare (developing on Brinch Hansen’s concepts) Synchronization.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings 1.
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.
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.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-5 Process Synchronization Department of Computer Science and Software.
Operating Systems CSE 411 CPU Management Dec Lecture Instructor: Bhuvan Urgaonkar.
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.
1 Processes and Threads Part II Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 6: Process Synchronization.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 5: Process Synchronization.
Chapter 6 Synchronization Dr. Yingwu Zhu. The Problem with Concurrent Execution Concurrent processes (& threads) often access shared data and resources.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Interprocess Communication Race Conditions
G.Anuradha Reference: William Stallings
Chapter 5: Process Synchronization
Concurrency: Mutual Exclusion and Synchronization
Lecture 2 Part 2 Process Synchronization
Critical section problem
Concurrency: Mutual Exclusion and Process Synchronization
CSE 451: Operating Systems Autumn 2003 Lecture 7 Synchronization
CSE 451: Operating Systems Autumn 2005 Lecture 7 Synchronization
CSE 451: Operating Systems Winter 2003 Lecture 7 Synchronization
CSE 153 Design of Operating Systems Winter 19
Chapter 6: Synchronization Tools
Other Synchrnization Problems
Process/Thread Synchronization (Part 2)
CSE 542: Operating Systems
CSE 542: Operating Systems
Presentation transcript:

Dr. Kalpakis CMSC 621, Advanced Operating Systems. Fall 2003 URL: Introduction & Process Synchronization Dr. Kalpakis Course URL:

CMSC 621, Fall URL: Topics of this course Process synchronization Process deadlocks Architectures of distributed systems Theoretical foundations of distributed systems Distributed mutual exclusion Distributed deadlock detection Distributed file systems Distributed shared memory Distributed scheduling Resource security and protection Queuing theory and system performance modeling Selected topics

CMSC 621, Fall URL: Why Operating Systems are needed? Ever tried to use or manage a computer without an OS? It is usually very Cumbersome Inefficient Unfriendly Thus, some S/W that eases the difficulties in using and managing computers will be very useful ($$s)

CMSC 621, Fall URL: Functions of an Operating System Resource management resources (CPU, memory, interrupts, disk, printers, displays, etc) Need to help in managing a resource’s Time & space synchronization & deadlocks accounting & state information User friendliness Addresses issues related to execution environment error detection & handling protection & security fault-tolerance & recovery

CMSC 621, Fall URL: Policies & Mechanisms Separate policies, which describe what should be done from mechanisms, which describe how policies are implemented In doing so, flexibility and adaptability policies decisions be made at higher levels, and can be implemented using a small fixed set of mechanisms policies can and do change over time as applications and users of resources change over time

CMSC 621, Fall URL: Design Approaches Basic design approaches Layered (Dijkstra) vertically apportion OS functions to set of layers Clearly defined interfaces and functionality for each layer Example OS: Multics Kernel (Hansen) kernel=collection of primitives used by the rest of the OS Contains at least process creation, control, and communication primitives. Example OS: Hydra Virtual Machine provides the illusion to the user that all machine hardware is at this disposal Example OS: VM/370 on IBM 370

CMSC 621, Fall URL: Types of Advanced Operating Systems OS can be classified depending on whether they are Architecture driven Distributed operating systems Concerned with lack of shared memory and physical global clock, and unpredictable communication delays Multiprocessor operating systems shared memory accessed by multiple processors Application driven database operating systems Concurrency control, transaction management, and recovery real-time operating systems soft and hard real-time process scheduling (minimizing tardy processes)

CMSC 621, Fall URL: Interacting Processes Process=program in execution Processes typically interact/cooperate with each other in order to provide various services Interaction can happen either by sharing a resource (eg memory location) or by exchanging messages Interacting processes need to coordinate in order to maintain the integrity constraints of the shared resources and to provide the intended service

CMSC 621, Fall URL: Processes A process during its lifetime goes can be in any of these states running ready blocked concurrent processes=their lifetimes overlap serial processes= their lifetimes (execution time period) do not overlap processes interact via shared variables or messages Process state information includes program counter, page tables, state, priorities, privileges, open file descriptors, pending I/Os, activation stack, register contents, etc Process switching/swapping is expensive threads are lightweight processes(execution threads) within a process which share common state information between them Threads have lower cost of switching/management than processes

CMSC 621, Fall URL: Critical Section Problem Critical section a code segment in which a shared resource is accessed In order to maintain integrity of shared resource mutual exclusion is needed The mutual exclusion problem (Mutex) requirements only 1 process is executing in CS when no process in CS any process can get in CS in finite time No process can prevent any other process to enter CS indefinitely Early mechanisms for Mutex busy waiting disabling interrups

CMSC 621, Fall URL: A Solution to the Critical Section Problem (Peterson’81) #define FALSE 0 #define TRUE 1 #define N 2 /* number of processes */ int turn; /* whose turn is it? */ int interested[N]; /* all values initially 0 (FALSE) */ void enter_region(int process) { /* process is 0 or 1 */ int other; /* number of the other process */ other = 1 - process; /* the opposite of process */ interested[process] = TRUE; /* show that you are interested turn = process; /* set flag */ while (turn == process && interested[other] == TRUE) ; /* wait */ } void leave_region(int process) { /* process: who is leaving */ interested[process] = FALSE; /* indicate departure from critical region */ }

CMSC 621, Fall URL: Semaphores (Dijkstra’65) A semaphore is an integer variable S with an associated queue and two operations P(S) if S >= 1 the S := S-1 else wait (block) on semaphore’s queue V(S) if queue not empty unblock a waiting process else S := S +1 Binary and integer semaphores (depending on the initial value of S) Mutex is achieved with binary semaphores S P(S); Critical Section Code; V(S); Drawbacks of semaphores processes need to know which other processes use the semaphores and how P & V operations must be placed carefully difficult to debug and verify

CMSC 621, Fall URL: Some Famous Synchronization Problems Dining Philosophers Producer-Consumer Readers-Writers reader’s priority: arriving readers have priority over waiting writers writer’s priority: an arriving writer has priority on waiting readers; an arriving/waiting reader gets in CS only if there not writers in the system starvation weak readers/writers Sleeping Barber Cigarette smokers

CMSC 621, Fall URL: Monitors (Hoare’74) ADT for defining shared objects and methods to access them Properties only one process can be active within a monitor at a time; all other processes are placed in an entry queue processes that are active within a monitor can only access local data monitor data can not be accessed from outside monitor Special operations wait active process joins a monitor queue and relinquishes control of the monitor signal signaling process joins the urgent queue and allows a waiting process to gain control/entry into the monitor urgent queue has higher priority than the entry queue

CMSC 621, Fall URL: Monitors Condition variables are monitor special variables enable wait and signal operations to be distinguished and hence provide finer synchronization have an associated queue where processes can wait Provide operations for processes to execute.wait[( )];.signal;.queue;

CMSC 621, Fall URL: Monitor Program Skeleton Monitor-name: monitor; begin : condition; procedure ; begin; …. … … if.queue then …. End; begin end;

CMSC 621, Fall URL: Drawbacks of Monitors no concurrency if shared resource is encapsulated in the monitor if not, then monitor methods need to be called before & after accessing shared resource integrity of shared resource is not ensured nested monitor calls can lead into deadlocks since a wait in an inner monitor relinquishes control of that monitor only, but not the outer monitor

CMSC 621, Fall URL: Serializers (Hewitt & Anderson’79) Serializers are similar to monitors all events that gain/release control are totally ordered in time only one processes is active in a serializer provide hollow regions where multiple processes can be active offer automatic signaling where a process specifies the resume condition at the time it makes the wait call processes entering a hollow region relinquishes control of the serializer join-crowd( ) then end where maintans the list of processes (ids) active in hollow region empty( ) tests whether any process is active in

CMSC 621, Fall URL: Serializer Queues Serializers have queue variables instead of condition variables enqueue(, ) until the is checked when a process reaches the head of the priority queue; if condition is true and no one is in the serializer, the waiting process regains control of serializer empty( ) tests whether is empty all events that gain/release control are totally ordered in time entry and exit events guarantee, establish, and timeout events (queue related) join-crowd and leave-crowd events

CMSC 621, Fall URL: Solving the Readers/Writers problem using Serializers serializer ReadersWriters { queue readq, writeq; crowd rcrowd, wcrowd; database db; data read(int key) { data x; enqueue(readq) until empty(wcrowd); joincrowd(rcrowd) { x = readDB(db, key); }; return x; }; void write(data x, int key) { enqueue(writeq) until empty(wcrowd) && empty(rcrowd) && empty(readq); joincrowd(wcrowd) { writeDB(db, x, key); }; }; }

CMSC 621, Fall URL: Drawbacks of Serializers Less efficient due to complexity and automatic signalling

CMSC 621, Fall URL: Path Expressions (Campbell & Habermann’74) a path expression is similar to a regular expression (with special operators) with alphabet the set of operations on the shared resource restricts the set of admissible execution histories of operations on the shared resource indicate inteleave order of shared resource operations

CMSC 621, Fall URL: Path Expressions Path expression path end, where is an expression with operands resource operations and the following three operators Sequencing (;) path open; read; close; end Selection (+) path read + write end concurrency ({}) path write; {read} end path {write; read} end If there are more than one path expressions then an admissible execution histories must satisfy all of them path startRead + {startWrite; write} end path {startRead; read} + write end

CMSC 621, Fall URL: Communicating Sequential Processes (Hoare’78) I/O commands can been treated as synchronization primitives In CSP processes communicate via I/O commands I/O commands are synchronous each I/O command specifies the name of the target input or output process an input and an output command correspond if type of output agrees with type of input variable I/O commands execute if they have matching source/destination processes and they correspond

CMSC 621, Fall URL: CSP Syntax CSP commands input command ? output command ! Concurrency [ || … || ] guarded command --> where E is a boolean expression (including an input command) a guarded command succeeds (i.e. L is executed) only if its guard evaluates to true alternative command [ # … # ] repetitive command *[ ]

CMSC 621, Fall URL: Solving the Producer/Consumer Problem with CSP process buffer { buf pool[0..9]; int in=0, out=0; *[ in in++; # out consumer!pool[out mod 10]; out++ ] } process producer { buf p; while (true) { p=produce(); buffer!p; } process consumer{ buf q; while(true){ buffer!more(); buffer?q; consume(q); } }

CMSC 621, Fall URL: Drawbacks of CSP explicit naming of processes in I/O commands introduces delays and inefficiencies due to the blocking I/O commands