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

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

Chapter 6: Process Synchronization. Module 6: Process Synchronization

Module 6: Process Synchronization

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

Lecture 3: Synchronization & Deadlocks

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

Module 6: Process Synchronization

Chapter 6: Process Synchronization

Process Synchronization

Process Synchronization

Chapter 6 Synchronization

Synchronization Principles

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

Chapter 6: Process Synchronization

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

Chapter 7: Process Synchronization!

Process Synchronization

Chapter 6: Synchronization

Chapter 6: Process Synchronization

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

CHAPTER 6: PROCESS SYNCHRONIZATION

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

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

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

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

Lesson 6: Process Synchronization

Chapters 5 and 6 Concurrency

Process Synchronization. CISC3595, Spring 2015 Dr. Zhang

Chapter 7: Process Synchronization. Background. Illustration

Chapter 6: Process Synchronization

Concept of a process

Chapter 5: Process Synchronization

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

Process Synchronization

Process Synchronization

CS370 Operating Systems

Process Synchronization

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

Process Synchronization

Chapter 6: Process Synchronization

Chapter 7: Process Synchronization. Background

Chapter 5: Process Synchronization

Introduction to Operating Systems

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

Chapter 7 Process Synchronization

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

IV. Process Synchronisation

Concurrency: Mutual Exclusion and Synchronization

Background. Module 6: Process Synchronization. Bounded-Buffer (Cont.) Bounded-Buffer. Background

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

Chapter 5: Process Synchronization

Process Synchronization

Dept. of CSE, York Univ. 1

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

CS370 Operating Systems

Real-Time Operating Systems M. 5. Process Synchronization

Lecture 5: Inter-process Communication and Synchronization

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

Deadlock. Concurrency: Deadlock and Starvation. Reusable Resources

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

Process Coordination

Concurrent Computing

1. Motivation (Race Condition)

Concurrency: Mutual Exclusion and

Process Co-ordination OPERATING SYSTEMS

Operating Systems Antonio Vivace revision 4 Licensed under GPLv3

PESIT Bangalore South Campus

Process Synchronisation (contd.) Deadlock. Operating Systems. Spring CS5212

Interprocess Communication By: Kaushik Vaghani

Chapter 6 Synchronization

Process Management And Synchronization

UNIT 2 Basic Concepts of CPU Scheduling. UNIT -02/Lecture 01

Comp 5311 Database Management Systems. 14. Timestamp-based Protocols

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

Mutual Exclusion and Synchronization

CSE Opera,ng System Principles

Chapter 6 Process Synchronization

Concurrency. On multiprocessors, several threads can execute simultaneously, one on each processor.

CSIT5300: Advanced Database Systems

Comp 310 Computer Systems and Organization

Synchronization Principles I

Process Synchronization

Multiversion Schemes to achieve Snapshot Isolation Timestamped Based Protocols

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

CS370 Operating Systems Midterm Review. Yashwant K Malaiya Spring 2019

Enforcing Mutual Exclusion Using Monitors

Process Synchronization(2)

Concurrency. On multiprocessors, several threads can execute simultaneously, one on each processor.

Dealing with Issues for Interprocess Communication

Process Synchronization(2)

OS Process Synchronization!

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

Deadlocks. Mehdi Kargahi School of ECE University of Tehran Spring 2008

Classic Problems of Synchronization

CS370: System Architecture & Software [Fall 2014] Dept. Of Computer Science, Colorado State University

Synchronization for Concurrent Tasks

Checkpoints. Logs keep growing. After every failure, we d have to go back and replay the log. This can be time consuming. Checkpoint frequently

CS420: Operating Systems. Process Synchronization

Synchronization I. Jo, Heeseung

Announcements. Office hours. Reading. W office hour will be not starting next week. Chapter 7 (this whole week) CMSC 412 S02 (lect 7)

Transcription:

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

Producer-Consumer (Bounded Buffer) Producer Consumer

Race Condition Producer Consumer

Critical Sections Structure of a Typical Process Requirements for Solving critical-section problem: Mutual exclusion Progress Bounded waiting

Two-Process Solutions Algorithm 1 Shared: int turn; P i : while (TRUE) { while (turn!=i); critical-section turn = 1-i; remainder-section } Mutual exclusion yes Progress no Bounded waiting yes

Two-Process Solutions Algorithm 2 Shared: boolean flag[2]; P i : flag[i] = FALSE; do { flag[i] = TRUE; while (flag[j]); critical-section flag[i] = FALSE; remainder-section } while (TRUE); Mutual exclusion yes Progress no Bounded waiting yes

Peterson s Solution

Eisenberg & McGuire Solution

Eisenberg & McGuire Solution

Synchronization Hardware Atomic instructions: TestAndSet

Synchronization Hardware Atomic instructions: Swap

Synchronization Hardware Spin lock Methods that use busy waiting n-process solution with bounded-waiting

Synchronization Hardware

Semaphores A semaphore S is an integer variable Two atomic operations

Semaphore Usage Critical-section Process synchronization Problems: Spin-lock & bounded-waiting

A Better Definition

Semantics The value of semaphore specifies the number of processes waiting on that semaphore It is assumed that wait and signal are executed atomically, while this is not simply valid Method 1: disabling interrupts to prevent interleaving of wait and signal operations on a semaphore In multiprocessor systems, interrupts on all processors should be disabled resulting in quite low performance Method 2: using one of the previous critical-section methods (busy waiting) More proper for MP systems Wait and signal have a few instructions resulting in short critical sections Busy waiting is not problematic

Deadlocks What is the difference between deadlock and starvation?

Classical Problems of Synchronization The bounded-buffer problem Producer Consumer

The Readers-Writers Problem Writer Reader

The Dining Philosophers Problem

The Dining Philosophers Problem Problem? Three solutions!! Is a deadlock-free solution also starvation-free?

Monitors Problems with semaphores (programming faults):

Syntax of a Monitor

A Monitor Scheme

Monitor with Condition Variables

When x.signal() is Invoked by P Two possibilities exist:

Dining-Philosophers Solution using Monitors

Dining-Philosophers Solution using Monitors

Implementing a Monitor using Semaphores External procedure F is replaced by x.wait() x.signal()

Resuming Processes within a Monitor x.wait(c), where c is called a priority number

Similar Mechanisms Down: wait Up: signal

Problems with Monitors

Atomic Transactions Transaction A collection of instructions that performs a single logical function A transaction may commit or abort When a transaction is aborted, the state of the data accessed by it is restored to what it was before executing that transaction, i.e., it is rolled back The execution of a transaction should be assumed as atomic

Different Types of Storage Volatile storage Non-Volatile storage Stable storage

Log-Based Recovery Log is stored on the stable storage Write-ahead log Every log precedes a single write operation by Transaction name Data item name Old value New value Special log records <T i starts> <T i commits>

Recovery Algorithm Undo(T i ): restores the value of all data updates by T i to the old values Redo(T i ): sets the value of all data updates by T i to the new values If T i aborts, we need to execute undo(t i ) After a system failure

Concurrent Atomic Transactions Serializability Restrictive Serial vs. non-serial schedules Serial Non-serial but serializable Conflicting operations: O i and O j are conflicting if they access the same data item and at least one of them is a write operation

Concurrent Atomic Transactions A conflict serializable schedule If a schedule S can be transformed to a serial schedule S by a series of swaps of non-conflicting operations

Locking Protocol Shared vs. exclusive lock Two-phase locking (2PL) protocol Properties Ensures conflict Serializability It is not deadlock-free There may be conflict-serializable schedules that cannot be obtained by 2PL Additional information on transactions may improve 2PL

Timestamp-Based Protocols Each transaction T i is assigned a timestamp in an ascending order of time by the system Each data item Q has two timestamps

Timestamp-Based Protocols If transaction T i issues read(q) If transaction T i issues write(q) Each transaction that is rolled is restarted with a new timestamp

Timestamp-Based Protocols Properties Deadlock-free: no transaction ever waits Not stronger than 2PL and vice versa