Concurrent & Distributed Systems Lecture 4: ME solutions Lecture 3 considered possible algorithms for achieving Mutual Exclusion between the critical sections.

Slides:



Advertisements
Similar presentations
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Advertisements

Operating Systems Part III: Process Management (Process Synchronization)
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.
CSC321 Concurrent Programming: §3 The Mutual Exclusion Problem 1 Section 3 The Mutual Exclusion Problem.
A Simple Critical Section Protocol There are N concurrent processes P 1,…,P N that share some data. A process accessing the shared data is said to execute.
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
Process Synchronization Continued 7.2 The Critical-Section Problem.
Previously… Processes –Process States –Context Switching –Process Queues Threads –Thread Mappings Scheduling –FCFS –SJF –Priority scheduling –Round Robin.
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.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles Seventh Edition By William Stallings.
Intertask Communication and Synchronization In this context, the terms “task” and “process” are used interchangeably.
Concurrency in Shared Memory Systems Synchronization and Mutual Exclusion.
Concurrent & Distributed Systems Lecture 3: Processes interacting by sharing resources Asynchronous processes can interact by sharing a common resource.
Concurrent & Distributed Systems Lecture 5: Semaphores and Synchronisation Concurrent processes which don’t interact in some way don’t form an interesting.
5.6 Semaphores Semaphores –Software construct that can be used to enforce mutual exclusion –Contains a protected variable Can be accessed only via wait.
5.6 Semaphores Semaphores –Software construct that can be used to enforce mutual exclusion –Contains a protected variable Can be accessed only via wait.
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.
Concurrent & Distributed Systems Lecture 10: Monitors What? –First of all, what NOT! The term ’monitor’ was used in the past for the mini operating system.
Chapter 2.3 : Interprocess Communication
Race Conditions CS550 Operating Systems. Review So far, we have discussed Processes and Threads and talked about multithreading and MPI processes by example.
Synchronization Solutions
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Process Synchronization.
Hardware solutions So far we have looked at software solutions for the critical section problem. –algorithms whose correctness does not rely on any other.
Operating Systems CSE 411 CPU Management Oct Lecture 13 Instructor: Bhuvan Urgaonkar.
Concurrency, Mutual Exclusion and Synchronization.
Process Synchronization Continued 7.2 Critical-Section Problem 7.3 Synchronization Hardware 7.4 Semaphores.
Semaphores, Locks and Monitors By Samah Ibrahim And Dena Missak.
1 Concurrency: Mutual Exclusion and Synchronization Module 2.2.
1 Chapter 2.3 : Interprocess Communication Process concept  Process concept  Process scheduling  Process scheduling  Interprocess communication Interprocess.
Operating Systems CSE 411 CPU Management Oct Lecture 14 Instructor: Bhuvan Urgaonkar.
Chap 6 Synchronization. Background Concurrent access to shared data may result in data inconsistency Maintaining data consistency requires mechanisms.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 9 th Edition Chapter 5: Process Synchronization.
Chapter 7 -1 CHAPTER 7 PROCESS SYNCHRONIZATION CGS Operating System Concepts UCF, Spring 2004.
Chapter 6 – Process Synchronisation (Pgs 225 – 267)
1 Concurrent Processes. 2 Cooperating Processes  Operating systems allow for the creation and concurrent execution of multiple processes  concurrency.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Module 6: Process Synchronization Background The.
Background Concurrent access to shared data may result in data inconsistency Maintaining data consistency requires mechanisms to ensure the orderly execution.
Operating Systems CMPSC 473 Mutual Exclusion Lecture 11: October 5, 2010 Instructor: Bhuvan Urgaonkar.
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.
Lecture 6: Monitors & Semaphores. Monitor Contains data and procedures needed to allocate shared resources Accessible only within the monitor No way for.
Synchronization CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han.
Operating System Concepts and Techniques Lecture 13 Interprocess communication-2 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and.
Process Synchronization. Objectives To introduce the critical-section problem, whose solutions can be used to ensure the consistency of shared data To.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 6: Process Synchronization.
CE Operating Systems Lecture 8 Process Scheduling continued and an introduction to process synchronisation.
Implementing Mutual Exclusion Andy Wang Operating Systems COP 4610 / CGS 5765.
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Chapter 6: Process Synchronization
Chapter 5: Process Synchronization
Background on the need for Synchronization
Process Synchronization
Chapter 5: Process Synchronization
Inter-Process Communication and Synchronization
Topic 6 (Textbook - Chapter 5) Process Synchronization
Lecture 22 Syed Mansoor Sarwar
Lecture 2 Part 2 Process Synchronization
Critical section problem
Concurrency: Mutual Exclusion and Process Synchronization
Implementing Mutual Exclusion
CSE 153 Design of Operating Systems Winter 19
Chapter 6: Synchronization Tools
Process/Thread Synchronization (Part 2)
Sarah Diesburg Operating Systems CS 3430
Presentation transcript:

Concurrent & Distributed Systems Lecture 4: ME solutions Lecture 3 considered possible algorithms for achieving Mutual Exclusion between the critical sections of processes sharing a resource. None of the algorithms were ideal (i.e. both safe, live and efficient). This lecture explains one example of an algorithm which is both safe and live (Dekkar’s algorithm). There are some others as well. The lecture also shows why new engineering tools, new computer hardware even, is needed to make real progress in the problems of concurrent processes. The first new tool is the semaphore

Concurrent & Distributed Systems Dekkar’s algorithm This is based on the safe version of the two keys algorithm (CCP6a) Process P1:= inCritical while P2 = inCritical do Begin {Dekkar's modification to the busy waiting} If turnToGo = 2 then Begin {P1 gives way by pretending} P1 := outOfCritical; While turnToGo = 2 do; {wait for P2 to exit CS} P1 := inCritical; End; End; {of Dekkar's modification} {critical section here} turnToGo := 2; P1 := outOfCritical Process 2 has the opposite logic, turnToGo can be initialised to either process Dekkar’s algorithm can be proved safe and live – this is the hard bit!

Concurrent & Distributed Systems Dekkar’s algorithm: 2 Dekkar’s algorithm was proved safe and live –Applies to 2 processes, in the version shown –Has quite complex pre-protocol Hence requires very close Quality Control (QA) –Can be extended to > 2 processes, but then Protocols much more complicated QA gets even worse –Still involves processes in ‘busy waiting’ loops Other algorithms have been invented –Eg Peterson’s algorithm, ‘bolt’ algorithms –All quite complex and difficult Lots of other research done, identifying –Need for atomic ‘test_and_set’ operations, or –Atomic exchange operations eg x:=:y

Concurrent & Distributed Systems Semaphores: Design Philosophy Existing methods not good (not even Dekkar’s algorithm) However the problem is very well understood (not having atomic operations such as test_and_set, or exchange operations) Engineering solution –Specify new tools in terms of abstract functionality (we know what we want) –Persuade someone to sort out the problems of implementing them Hardware manufactures, chip designers –Modern CPUs do have ‘test and set’ and ‘exchange’ instructions Software designers, i.e. Operating Systems designers Concurrent & Distributed Systems are so important that many such modern tools now exist. The first, and still very important (still underpins lots of concurrency in Unix, Linux etc) was the Semaphore. –Named after the first systems of digital communication (~300 years ago)

Concurrent & Distributed Systems Semaphores: The abstraction A semaphore is a protected integer system entity with special attributes: –Sem4’s have an identifier –Concurrent systems can employ many sem4’s (with different identifiers) –Sem4’s are globally accessible by concurrent processes needing to use them (this means that in practice the processes need access to the same memory address space – so sem4’s are not really for distributed systems, where other equivalent tools will be needed. –Access to sem4’s by processes is atomic (cannot be interleaved or interfered with by other processes using the same sem4). –Each Sem4 has a queue of waiting processes (which could be empty). Processes can only use sem4’s via three ‘system calls’ –Access to these system calls may be limited to ‘protected code’ coming from system programmers etc (cf accessor methods in Java and the philosophy of encapsulation/object oriented programming/agents etc) Semaphores can be binary (boolean) sem4’s (whose value can only ever be 0 or 1) or counting (general) sem4’s (can have any +ve value) Semaphores come in ‘Strong’ and ‘Weak’ varieties, defined by the type of their associated queues,

Concurrent & Distributed Systems Semaphore system calls Processes can use a sem4 ‘tool’ by using one of three system calls. The action of each call is atomic and must be implemented to follow exactly the definitions below: Initialise(s,x) –Creates a new sem4 with s as its identifier and x as its initial value Wait(s) –If s = 0 then the calling process is added to the sem4’s queue of waiting processes (sem4 calls are part of the operating system kernel, so while processes are in a sem4 queue, they do not get time from the scheduler – so no ‘busy waiting’ losses. –Id s > 0 then the calling process continues executing and s:=s-1. Signal(s) –If there is one or more processes in the sem4’s queue of waiting processes, then one of them * is ‘woken up’, ie the scheduler will give it time again and the process can continue. –If not, the calling process continues and s:=s+1 * which one – this depends on what kind of queue –Strong sem4’s have FIFO queues, Weak sem4’s have other kinds (eg priority based) of queues - with advantages and disadvantages.

Concurrent & Distributed Systems Mutual Exclusion by using Sem4’s :1 (CCP7) Sem4’s can be used to make Critical Sections Mutually Exclusive Initialise the sem4 to 0 eg initialise (s,1) Safe. Live (actions are atomic, so no interleaving problems), but must be used properly. Can be applied to a Critical Section shared by any number of processes Can ‘look after’ any number of shared resources (one sem4 for each) Turnstile 1 Repeat ---- wait(s) X := Nv X := X+1 Nv := X Signal(s) ---- Until no more admissions Turnstile 2 Repeat ---- wait(s) Y := Nv Y := X+1 Nv := Y signal(s) ---- Until no more admissions Linked pair of Critical Sections