1 Shared Memory. 2 processes 3 Types of Shared Variables Read/Write Test & Set Read-Modify-Write.

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

CS 603 Process Synchronization: The Colored Ticket Algorithm February 13, 2002.
Mutual Exclusion – SW & HW By Oded Regev. Outline: Short review on the Bakery algorithm Short review on the Bakery algorithm Black & White Algorithm Black.
Operating Systems Part III: Process Management (Process Synchronization)
Synchronization and Deadlocks
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
Mutual Exclusion By Shiran Mizrahi. Critical Section class Counter { private int value = 1; //counter starts at one public Counter(int c) { //constructor.
ALICE AND BOB DISCOVER THE PETERSON'S ALGORITHM COSC 4330/6310 Summer 2013.
Concurrent Programming Problems OS Spring Concurrency pros and cons Concurrency is good for users –One of the reasons for multiprogramming Working.
Concurrency: Mutual Exclusion and Synchronization - Chapter 5 (Part 2)
Chapter 6 Process Synchronization Bernard Chen Spring 2007.
Multiprocessor Synchronization Algorithms ( ) Lecturer: Danny Hendler The Mutual Exclusion problem.
Local-spin, Abortable Mutual Exclusion Joe Rideout.
Parallel Processing (CS526) Spring 2012(Week 6).  A parallel algorithm is a group of partitioned tasks that work with each other to solve a large problem.
Cpr E 308 Spring 2004 Recap for Midterm Introductory Material What belongs in the OS, what doesn’t? Basic Understanding of Hardware, Memory Hierarchy.
THIRD PART Algorithms for Concurrent Distributed Systems: The Mutual Exclusion problem.
CPSC 668Set 7: Mutual Exclusion with Read/Write Variables1 CPSC 668 Distributed Algorithms and Systems Fall 2009 Prof. Jennifer Welch.
Multiprocess Synchronization Algorithms ( )
Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 91 Today’s class Mutual exclusion and synchronization 
CPSC 668Set 6: Mutual Exclusion in Shared Memory1 CPSC 668 Distributed Algorithms and Systems Fall 2006 Prof. Jennifer Welch.
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.
CPSC 668Set 6: Mutual Exclusion in Shared Memory1 CPSC 668 Distributed Algorithms and Systems Fall 2009 Prof. Jennifer Welch.
5.6 Semaphores Semaphores –Software construct that can be used to enforce mutual exclusion –Contains a protected variable Can be accessed only via wait.
Concurrent Processes Lecture 5. Introduction Modern operating systems can handle more than one process at a time System scheduler manages processes and.
Chapter 6: Process Synchronization. Outline Background Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores Classic Problems.
OS Spring’04 Concurrency Operating Systems Spring 2004.
Bakery Algorithm - Proof
Process Synchronization
Synchronization in Distributed Systems. Mutual Exclusion To read or update shared data, a process should enter a critical region to ensure mutual exclusion.
Concurrency in Distributed Systems: Mutual exclusion.
1 Interprocess Communication Race Conditions Two processes want to access shared memory at same time.
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.
1 Chapter 5 Concurrency. 2 Concurrency 3 4 Mutual Exclusion: Hardware Support Test and Set Instruction boolean testset (int *i) { if (*i == 0) { *i.
Operating Systems CSE 411 CPU Management Oct Lecture 13 Instructor: Bhuvan Urgaonkar.
Process Synchronization Continued 7.2 Critical-Section Problem 7.3 Synchronization Hardware 7.4 Semaphores.
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.
Cpr E 308 Spring 2004 Real-time Scheduling Provide time guarantees Upper bound on response times –Programmer’s job! –Every level of the system Soft versus.
6.852: Distributed Algorithms Spring, 2008 Class 13.
THIRD PART Algorithms for Concurrent Distributed Systems: The Mutual Exclusion problem.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
1 Program5 Due Friday, March Prog4 user_thread... amount = … invoke delegate transact (amount)... mainThread... Total + = amount … user_thread...
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 9 th Edition Chapter 5: Process Synchronization.
DISTRIBUTED ALGORITHMS AND SYSTEMS Spring 2014 Prof. Jennifer Welch CSCE
CY2003 Computer Systems Lecture 04 Interprocess Communication.
CSCE 668 DISTRIBUTED ALGORITHMS AND SYSTEMS Spring 2014 Prof. Jennifer Welch CSCE 668 Set 8: More Mutex with Read/Write Variables 1.
Operating Systems CMPSC 473 Mutual Exclusion Lecture 11: October 5, 2010 Instructor: Bhuvan Urgaonkar.
Synchronicity Introduction to Operating Systems: Module 5.
CPSC 668 DISTRIBUTED ALGORITHMS AND SYSTEMS Fall 2011 Prof. Jennifer Welch CSCE 668 Set 6: Mutual Exclusion in Shared Memory 1.
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
Chapter 10 Mutual Exclusion Presented by Yisong Jiang.
6.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles 6.5 Semaphore Less complicated than the hardware-based solutions Semaphore S – integer.
CSCE 668 DISTRIBUTED ALGORITHMS AND SYSTEMS
Process Synchronization: Semaphores
Concurrency: Mutual Exclusion and Synchronization
Designing Parallel Algorithms (Synchronization)
Concurrent Distributed Systems
Midterm review: closed book multiple choice chapters 1 to 9
Threading And Parallel Programming Constructs
CSCE 668 DISTRIBUTED ALGORITHMS AND SYSTEMS
Mutual Exclusion Problem Specifications
Lecture 2 Part 2 Process Synchronization
Mutual Exclusion CS p0 CS p1 p2 CS CS p3.
Multiprocessor Synchronization Algorithms ( )
Course Syllabus 1. Introduction - History; Views; Concepts; Structure
Syllabus 1. Introduction - History; Views; Concepts; Structure
Presentation transcript:

1 Shared Memory

2 processes

3 Types of Shared Variables Read/Write Test & Set Read-Modify-Write

4 Read/Write Variables Read(v)Write(v,a) return(v); v = a; Or simpler: x = v; v = x; (read v) (write v)

5 write 10

6 10

7 write read

8 write read 10

9 write 10 write 20 Simultaneous writes

10 write 10 write 20 Slower process Possibility 1 20 Simultaneous writes

11 write 10 write 20 Slower process Possibility 2 10 Simultaneous writes

12 write In general: write x Simultaneous writes

13 write Slower process: write Simultaneous writes

14 read Simultaneous Reads a

15 read Simultaneous Reads aa a All read the same value

16 Test&Set Variables Test&Set(v) temp = v; v = 1; return (temp); Reset(v) v = 0; v is a binary variable

17 0

18 test&set 0

19 test&set 0 1

20 test&set 1

21 test&set 11

22 1

23 reset 0

24 test&set 0 simultaneous accesses test&set

25 test&set 1 simultaneous accesses 0 test&set 1 1 Faster process

26 Read-Modify-Write Variables RMW(v, f) temp = v; v = f(v); return (temp); function on v

27 0

28 RMW(+5) 0

RMW(+5)

30 RMW(+8) 5

RMW(+8)

32 0 simultaneous accesses RMW(+5) RMW(+8)

33 13 simultaneous accesses RMW(+5) RMW(+8) 8 0 Faster process

34 0 simultaneous accesses RMW(+5) RMW(+8) RMW(+10)

35 23 simultaneous accesses RMW(+5) RMW(+8) RMW(+10) fastest middle slower

36 RMW(v, f) temp = v; v = f(v); return (temp); RMW simulate Test&Set Test&Set(v) temp = v; v = 1; return (temp); Reset(v) v = 0; (f(v) = 1) RMW(v, f) temp = v; v = f(v); return (temp); (f(v) = 0)

37 Mutual Exclusion

38 Process 1 - program V = 1; For (x = 10; x< y; x++) { cout << “hello”; } If (t > 10) then while (x < 100) m = 20; ……

39 Process 1 - program Remainder code Critical Section Remainder Code Process 2 - program Remainder code Critical Section Remainder Code Only one process can enter the critical section Critical Section

40 Process 1 - program Remainder code Critical Section Remainder Code Process 2 - program Remainder code Critical Section Remainder Code Processes may update the same variables in the critical section Critical Section v = v+10;

41 Process 1 Remainder code Entry code Critical Section Exit code Remainder Code Process 2 Remainder code Entry Code Critical Section Exit Code Remainder Code Mutual Exclusion Entry/Exit code guaranty that only one process is in the critical section

42 Process 1 Remainder code Entry code Critical Section Exit code Remainder Code Process 2 Remainder code Entry Code Critical Section Exit Code Remainder Code Mutual Exclusion

43 Process 1 Remainder code Entry code Critical Section Exit code Remainder Code Process 2 Remainder code Entry Code Critical Section Exit Code Remainder Code Mutual Exclusion

44 Process 1 Remainder code Entry code Critical Section Exit code Remainder Code Process 2 Remainder code Entry Code Critical Section Exit Code Remainder Code Mutual Exclusion

45 Process 1 Remainder code Entry code Critical Section Exit code Remainder Code Process 2 Remainder code Entry Code Critical Section Exit Code Remainder Code Mutual Exclusion

46 Process 1 Remainder code Entry code Critical Section Exit code Remainder Code Process 2 Remainder code Entry Code Critical Section Exit Code Remainder Code Mutual Exclusion

47 Mutual Exclusion Critical Exit Remainder Entry

48 Attributes of mutual exclusion algorithms No Deadlock: if some process is in the entry section then some process will enter the critical region No Lockout: if some process is in the entry section then the same process will enter the critical region

49 Mutual Exclusion test&set variables

50 While (test&set(v) = 1) Critical section Reset (v) Entry: Exit:

51 0 test&set entry v

52 1 critical section v 0

53 0 exit v reset

54 0 test&set entry v Two processors entry test&set

55 1 entry v critical section 0 1

56 1 entry v critical section 0 test&set

57 1 entry v critical section 0 1

58 0 entry v exit reset test&set

59 1 critical section v 0

60 0 exit v reset

61 1 entry v critical section test&set Problem: the algorithm doesn’t guaranty no lockout, a process may starve Example: may never enter the critical section

62 1 entry v critical section test&set Example: may never enter the critical section

63 1 entry v critical section test&set Example: may never enter the critical section : faster than

64 Mutual exclusion read-modify-write variables

65 v.first v.last Ticket of current process in critical section Ticket of last process waiting in entry section Shared variable v

66 p = RMW(v, (v.first, v.last +1)) Repeat q = RMW(v,v) Until q.first = p.last Critical section RMV(v, (v.first+1, v.last)) Entry: Exit: (p and q are local variables)

67 v.first 1 v.last 1

68 v.first 1 v.last 1 p.last

69 v.first 1 v.last 2 entry p.last1

70 v.first 1 v.last 2 critical section p.last1

71 v.first 2 v.last 2 exit p.last1

72 v.first 1 v.last 1 Four processes p.last

73 v.first 1 v.last 2 p.last1 entry

74 v.first 1 v.last 2 p.last1 entry

75 v.first 1 v.last 3 p.last1200 entry

76 v.first 1 v.last 3 p.last1200 entry

77 v.first 1 v.last 4 p.last1230 entry

78 v.first 1 v.last 4 p.last1230 entry

79 v.first 1 v.last 5 p.last1234 entry

80 v.first 1 v.last 5 p.last1234 critical section entry

81 v.first 2 v.last 5 p.last1234 entry exit

82 v.first 2 v.last critical section entry

83 v.first 3 v.last entry exit

84 v.first 3 v.last 4 34 entry

85 v.first i v.last-1 i+k i critical section entry i+1 entry The behavior is similar with a queue …… (head) (tail)

86 Good features of algorithm: Guarantees no lockout (any process will eventually enter the critical section) Uses only one shared variable (v)

87 A problem: values can grow unbounded ii+1 … i+k …

88 Solution: a circular queue …… 1 2 n (for n processes) v.firstv.last-1 Only n different values are needed