CIS 720 Lecture 2. Concurrency …shared variable declaration…. …shared variable initialization… co P 1 // P 2 // P 3 // P 4 oc Execution of P 1 … P 4 starts.

Slides:



Advertisements
Similar presentations
Operating Systems Semaphores II
Advertisements

Ken Birman 1. Refresher: Dekers Algorithm Assumes two threads, numbered 0 and 1 CSEnter(int i) { int J = i^1; inside[i] = true; turn = J; while(inside[J]
Operating Systems Part III: Process Management (Process Synchronization)
1 Lecture 11: Transactions: Concurrency. 2 Overview Transactions Concurrency Control Locking Transactions in SQL.
Transaction Management: Concurrency Control CS634 Class 17, Apr 7, 2014 Slides based on “Database Management Systems” 3 rd ed, Ramakrishnan and Gehrke.
Process Synchronization A set of concurrent/parallel processes/tasks can be disjoint or cooperating (or competing) With cooperating and competing processes.
CS492B Analysis of Concurrent Programs Lock Basics Jaehyuk Huh Computer Science, KAIST.
Ch 7 B.
Transactions (Chapter ). What is it? Transaction - a logical unit of database processing Motivation - want consistent change of state in data Transactions.
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.
Operating System Concepts and Techniques Lecture 12 Interprocess communication-1 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and.
Operating Systems CMPSC 473 Mutual Exclusion Lecture 13: October 12, 2010 Instructor: Bhuvan Urgaonkar.
Day 14 Concurrency. Software approaches Programs must be written such that they ensure mutual exclusion. Petersons and Dekkers (Appendix B)
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization.
University of Pennsylvania 9/19/00CSE 3801 Concurrent Processes CSE 380 Lecture Note 4 Insup Lee.
A. Frank - P. Weisberg Operating Systems Introduction to Cooperating Processes.
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Process Synchronization.
Adopted from and based on Textbook: Operating System Concepts – 8th Edition, by Silberschatz, Galvin and Gagne Updated and Modified by Dr. Abdullah Basuhail,
Process Synchronization Ch. 4.4 – Cooperating Processes Ch. 7 – Concurrency.
Operating Systems CSE 411 CPU Management Oct Lecture 13 Instructor: Bhuvan Urgaonkar.
INTRODUCTION TO TRANSACTION PROCESSING CHAPTER 21 (6/E) CHAPTER 17 (5/E)
CIS 720 Concurrency Control. Locking Atomic statement –Can be used to perform two or more updates atomically Th1: …. ;……. Th2:…………. ;…….
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 8, 2005 Background Concurrent.
Object Oriented Analysis & Design SDL Threads. Contents 2  Processes  Thread Concepts  Creating threads  Critical sections  Synchronizing threads.
Concurrency, Mutual Exclusion and Synchronization.
02/23/2005Yan Huang - CSCI5330 Database Implementation – Transaction Transaction I.
6.3 Peterson’s Solution The two processes share two variables: Int turn; Boolean flag[2] The variable turn indicates whose turn it is to enter the critical.
Operating Systems CMPSC 473 Mutual Exclusion Lecture 14: October 14, 2010 Instructor: Bhuvan Urgaonkar.
CDA COLLEGE ACC101: BOOK KEEPING II Lecture 10 Lecture 10 Lecturer: Kleanthis Zisimos.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization.
Chapter 7 -1 CHAPTER 7 PROCESS SYNCHRONIZATION CGS Operating System Concepts UCF, Spring 2004.
Synchronizing Threads with Semaphores
Java Thread and Memory Model
Concurrency Control 1 Fall 2014 CS7020: Game Design and Development.
Chapter 15: Transactions Loc Hoang CS 157B. Definition n A transaction is a discrete unit of work that must be completely processed or not processed at.
CIS 720 Correctness of Concurrent Programs. i := 1 max := A[1] do i < n  i = i + 1 if (max < A[i]) max = A[i] od.
CM Name : p.rajesh Year/Semester : VI Semester Subject : Advanced database system Subject Code : CM-603 Topic : Advanced database concepts Duration.
Lecture 6: Monitors & Semaphores. Monitor Contains data and procedures needed to allocate shared resources Accessible only within the monitor No way for.
Operating Systems Lecture Notes Synchronization Matthew Dailey Some material © Silberschatz, Galvin, and Gagne, 2002.
Transaction Processing Concepts Muheet Ahmed Butt.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
CIS 720 Lecture 5. Techniques to avoid interference Disjoint variables –If the write set of each process is disjoint from the read and write set of other.
1 Critical Section Problem CIS 450 Winter 2003 Professor Jinhua Guo.
Process Synchronization. Objectives To introduce the critical-section problem, whose solutions can be used to ensure the consistency of shared data To.
Synchronization Questions answered in this lecture: Why is synchronization necessary? What are race conditions, critical sections, and atomic operations?
Concurrency 2 CS 2110 – Spring 2016.
Transactional Information Systems - Chapter 2. ML Lab 나 용 찬
Background on the need for Synchronization
Chapter 6-7: Process Synchronization
What I Teach (Do what I say, not what I do)
CIS 720 Concurrency Control.
Semaphore Originally called P() and V() wait (S) { while S <= 0
Process Synchronization
Lecture 19 Syed Mansoor Sarwar
Module 7a: Classic Synchronization
Transaction management
CIS 720 Lecture 5.
CIS 720 Lecture 4.
CIS 720 Lecture 4.
CS561 Computer Architecture Hye Yeon Kim
CIS 720 Lecture 2.
CIS 720 Lecture 4.
CIS 720 Lecture 4.
CIS 720 Lecture 2.
CIS 720 Lecture 4.
Presentation transcript:

CIS 720 Lecture 2

Concurrency …shared variable declaration…. …shared variable initialization… co P 1 // P 2 // P 3 // P 4 oc Execution of P 1 … P 4 starts concurrently and the co-oc statement completes when all blocks have completed execution.

Banking System Deposit(amount, account) { x = db.account; x = x + amount; db.account = x; } Transaction 1: Deposit $50 in Acc1 Transaction 2: Deposit $70 in Acc1 Possible interleavings T1.x = db.Acc1; T1.x = T1.x + 50 T2.x = db.Acc1; T2.x = T2.x + 70; db.Acc1 = T1.x db.Acc1 = T2.x Acc1 = 100 T1.x = 150; Acc1 =100 T2.x = 170; Acc1 = 100 Acc1 = 150 Acc1 = 170

Producer/consumer int p = 0; c = 0 co producer: // consumer: while (true) while(true) while (p!= c); while (p==c); p++; c++; buf = new_item item = buf oc

Producer/consumer int p = 0; c = 0 co producer: // consumer: while (true) while(true) while (p!= c); while (p==c); buf = new_item; item = buf; p++ c++ oc

Concurrent blocks in a cobegin statement may interfere with one another since the execution is not atomic Only some of the interleavings may lead to correct answers. Additional synchronization is required to ensure that only those interleavings occur.

Atomic execution Process: a sequence of statements Each statement is a sequence of atomic actions Action action: indivisible action that changes the program state Fine-grained atomic action: an atomic action implemented by the hardware.

Independence of processes Independence of parallel processes: – Read set: set of variables read by a block – Write set: set of variables updated by a block If the following pairs are disjoint (read set of P, write set of Q) (write set of P, read set of P) (write set of P, write set of Q) then P and Q are independent Independent blocks can execute without interference. They are atomic with respect to each other

Example 2 int x = 0; z = 5; y = 0 co P: x = x + 1 x = x + z // Q: y = z – 1 oc Read x; Add 1; Write x; Read z Read x Add x to z Write x Read z; Sub 1; Write y; Read x; Add 1; Write x; Read z Read x Add x to z Write x Read x; Add 1; Write x; Read z Read x Add x to z Write x Read z; Sub 1; Write y; Read z; Sub 1; Write y; P.read = {x,z}, P.write = {x} Q.read = {z}, Q.write = {y}

Finding max in an array A[0..N-1] Find_max(A,N) { co // int m1 = A[0] int m2 = A[N/2] for (int i=1;i<N/2;i++) for (int j = N/2 + 1; j < N; j++); if (m1 < A[i]) m1 = A[i]; if (m2 < A[j]) m2 = A[j] oc if m1 < m2 then return m2 else return m1 }

Examples (contd) int x = 0; co x = x + 1 // x = x – 1 oc

At-Most-Once Property Critical reference in an expression is a reference to a variable that is changed by another process. x = e satisfies at-most-once property if either – e contains at most one critical reference and x is not read by another process, or – e contains no critical references (in which case, x can be read by others) If an assignment statement meets this property then its execution will appear to be atomic

Example int x = 0; y = 0 co x = x + 1 // y = y + 1 oc int x = 0; y = 0 co x = y + 1 // y = y + 1 oc int x = 0; y = 0 co x = y + 1 // y = x + 1 oc

Example int x = 0; y = 0 co x = x + 1 // y = y + 1 oc int x = 0; y = 0 co x = y + 1 // y = y + 1 oc int x = 0; y = 0 co x = y + 1 // y = x + 1 oc Read y; Add 1; Write x; Read y; Add 1; Write y;

Synchronization statements : S is executed atomically : The execution of S is delayed until B is true. No other statement executes between evaluation of B to true and execution of S. Thus, B is guaranteed to be true when S is executed.

Examples 0  count++> vs while (count <= 0) {}; count++ int x = 0; y = 0; co // oc

Readers/writer problem Reader: read Writer: write

Producer/consumer Int p = 0; c = 0 co producer: // consumer: while (true) while(true) <await(p== c)  < await (p!=c)  buf = new_item; item = buf; p++ > c++> oc

Producer/consumer int p = 0; c = 0 co producer: // consumer1: // consumer2: while (true) while(true) while(true) < await (p!=c)  < await(p!=c)  buf = new_item; item1 = buf; item2 = buf p++ c++> c++> oc