Concept of a process

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

Example of use. Shared var mutex: semaphore = 1; Process i. begin.. P(mutex); execute CS; V(mutex);.. End;

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

CSC501 Operating Systems Principles. Process Synchronization

Process Synchronization

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

Process Management And Synchronization

Process Synchronization

Concurrency. Chapter 5

Process Coordination

Semaphores INF4140. Lecture 3. 0 Book: Andrews - ch.04 ( ) INF4140 ( ) Semaphores Lecture 3 1 / 34

OS Process Synchronization!

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

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

Synchronization Principles

CHAPTER 6: PROCESS SYNCHRONIZATION

Semaphores. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Dealing with Issues for Interprocess Communication

Last Class: Synchronization

Chapter 8. Basic Synchronization Principles

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

Process Synchronization. studykorner.org

Dept. of CSE, York Univ. 1

Chapter 6: Process Synchronization

Process Synchronization

2 Threads vs. Processes

Silberschatz and Galvin Chapter 6

CS3502 OPERATING SYSTEMS

Process Synchronization

Chapters 5 and 6 Concurrency

Chapter 6: Process Synchronization

Lesson 6: Process Synchronization

1. Motivation (Race Condition)

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

IT 540 Operating Systems ECE519 Advanced Operating Systems

Introduction to Operating Systems

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

Midterm on next week Tuesday May 4. CS 361 Concurrent programming Drexel University Fall 2004 Lecture 9

Midterm Exam. October 20th, Thursday NSC

Chapter 5 Concurrency: Mutual Exclusion and Synchronization

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

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

Concurrency: Mutual Exclusion and Synchronization

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

CS370 Operating Systems

IV. Process Synchronisation

Chapter 2 Processes and Threads. Interprocess Communication Race Conditions

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

CS370 Operating Systems

Global Environment Model

Synchronization. CSE 2431: Introduction to Operating Systems Reading: Chapter 5, [OSC] (except Section 5.10)

Chapter 7: Process Synchronization!

CS3733: Operating Systems

Concurrency: Principles of Deadlock. Processes and resources. Concurrency and deadlocks. Operating Systems Fall Processes need resources to run

Lecture 3: Intro to Concurrent Processing using Semaphores

Explain briefly how starvation may occur in process scheduling. (2 marks)

Topic 4: Synchronization with Semaphores

Process Synchronization

CS 471 Operating Systems. Yue Cheng. George Mason University Fall 2017

Chapter 5: Process Synchronization

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

CS420: Operating Systems. Process Synchronization

Semaphores. Otto J. Anshus University of {Tromsø, Oslo}

Chapter 7: Process Synchronization. Background

Concurrency and Synchronisation. Leonid Ryzhyk

Chapter 6: Process Synchronization

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 7: Process Synchronization. Background. Illustration

Concurrency: Deadlock and Starvation. Chapter 6

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

Basic Synchronization Principles

Synchronization. Peter J. Denning CS471/CS571. Copyright 2001, by Peter Denning

Deadlock. Concurrency: Deadlock and Starvation. Reusable Resources

Synchronization for Concurrent Tasks

PROCESS SYNCHRONIZATION

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

Process Synchronization

Process Synchronization

CS370 Operating Systems

Process/Thread Synchronization

Concurrency pros and cons. Concurrent Programming Problems. Linked list example. Linked list example. Mutual Exclusion. Concurrency is good for users

COP 4225 Advanced Unix Programming. Synchronization. Chi Zhang

CS 153 Design of Operating Systems Winter 2016

Process & Thread Management II. Queues. Sleep() and Sleep Queues CIS 657

Process & Thread Management II CIS 657

Operating Systems ECE344

EI 338: Computer Systems Engineering (Operating Systems & Computer Architecture)

Lecture. DM510 - Operating Systems, Weekly Notes, Week 11/12, 2018

Semaphores (and Eventcounts) Otto J. Anshus University of {Tromsø, Oslo}

Synchronization Spinlocks - Semaphores

Synchronization. Before We Begin. Synchronization. Credit/Debit Problem: Race Condition. CSE 120: Principles of Operating Systems.

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

Last class: Today: CPU Scheduling. Start synchronization

Process Synchronization Mechanisms

Process Synchronization

Process Synchronization. CISC3595, Spring 2015 Dr. Zhang

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

Opera&ng Systems ECE344

Learning Outcomes. Concurrency and Synchronisation. Textbook. Concurrency Example. Inter- Thread and Process Communication. Sections & 2.

Transcription:

Concept of a process In the context of this course a process is a program whose execution is in progress States of a process: running, ready, blocked Submit Ready Running Completion Blocked

Concurrent processes In a multiprocessor system two or more processes can be executing at the same time physical concurrency - as opposed to logical concurrency achieved by interleaving process execution Concurrent processor interaction: shared variables message passing If they don t interact their execution is functionally the same as their serial execution

The critical section problem A critical section is a code segment of a concurrent process in which a shared resource is accessed Concurrent access to a shared variable is potentially dangerous example: if a=0, what is the result of the command a=a+1 executed simultaneously by processes A and B? a common solution is the mutual exclusion ie serialization of accesses

Early Solutions Busy Waiting Wastes cycles Disabling Interrupts Only applicable to uniprocessors A special test-and-set instruction

Example of busy waiting on a lock (1/2) One could think of using a variable as a flag to be checked upon entering a critical section but the lock itself is a critical section! Possible race condition Shared integer lock = 0; Process i while lock == 1; lock = 1; execute CS; lock = 0; Process A while lock == 1; lock = 1; Process B while lock == 1; lock = 1;

Example of busy waiting on a lock (2/2) The correct implementation uses a test-and-set instruction to avoid race conditions Semantic of test-and-set instruction int test-and-set (int a) { int rv = a; a = 1; return rv; } Correct lock implementation Process A Shared integer lock = 0; While( test-and-set(lock) ==1) ;

Locks: pros and cons Pros: simple and fast ubiquitous: every processor has a test-and-set or equivalent operation Cons: busy waiting is wasteful of resources (CPU cycles, memory bandwidth)

Semaphores - definition Proposed by Dijkstra, it was the first high level constructs used to synchronize concurrent processes A semaphore S is an integer variable on which two atomic operations are defined, P(S) and V(S), and has an associated queue P and V semantics: P(S): if S 1 then S := S - 1 else <block and enqueue the process>; V(S): if <some process is blocked on the queue> then <unblock a process> else S := S + 1;

Semaphores - properties The P operation may block a process, but V does not Two type of semaphores binary: intial value is 1 resource counting: any initial value P and V are atomic operations P(S): if S 1 then S := S - 1 else <block and enqueue the process>; V(S): if <some process is blocked on the queue> then <unblock a process> else S := S + 1;

Example of use Shared var mutex: semaphore = 1; Process i begin P(mutex); execute CS; V(mutex); End;

Other synchronization problems Semaphore can be used in other synchronization problems besides Mutual Exclusion The Producer-Consumer problem a finite buffer pool is used to exchange messages between producer and consumer processes The Readers-Writers Problem reader and writer processes accessing the same file The Dining Philosophers Problem five philosophers competing for a pair of forks

Reader-Writers problem The shared resource is a file accessed by both reader and writer processes The synchronization constraints are: readers should be able to concurrently access the file only one writer at a time can access the file readers and writers exclude each others Variants: reader s priority: arriving readers have priority over waiting writers writer s priority: writers have priority over waiting readers

Simple Readers-Writers solution The following scheme is very simple but does not allow concurrent reader access Procedure reader P(mutex) <read file> V(mutex) Procedure writer P(mutex) <write file> V(mutex)

Readers-Writers solution with concurrent reader access Procedure reader P(reader_mutex) if readers = 0 then readers = readers + 1 P(writer_mutex) else readers = readers + 1 V(reader_mutex) <read file> Procedure writer P(writer_mutex) <write file> V(writer_mutex) P(reader_mutex) readers = readers - 1 if readers == 0 then V(writer_mutex) V(reader_mutex)

Readers-Writers with reader s priority Procedure reader P(reader_mutex) if readers = 0 then readers = readers + 1 P(writer_mutex) else readers = readers + 1 V(reader_mutex) Procedure writer P(sr_mutex) P(writer_mutex) <write file> V(writer_mutex) V(sr_mutex) <read file> P(reader_mutex) readers = readers - 1 if readers == 0 then V(writer_mutex) V(reader_mutex)