5.1.1 A Simple Example( 3/4 Uniprocessor Process p1 Process p2 chin getchar (ix chin getchar()iY chou七 chin putchar(shout)i ch。ut=chin; putchar(chou)i
12 5.1.1 A Simple Example(3/4) . chin = getchar(); . . . chout = chin; putchar(chout); . Process P2 . . chin = getchar(); chout = chin; putchar(chout); . . . Process P1 . Uniprocessor: X Y
5.1.1 A Simple Example( 4/4 Multiprocessor Process p1 Process p2 chin getchar (ix chin getchar()iY ch。ut=chin; chou七=chin putchar(chou)i putchar(shout)i
5.1.1 A Simple Example(4/4) . chin = getchar(); . chout = chin; putchar(chout); . . Process P2 . . chin = getchar(); chout = chin; . putchar(chout); . Process P1 . Multiprocessor: Y X 13
5.1 Principles of concurrent 5.1.0 What is concurrency .5.1.1 A Simple example ·5.1.2 Race Condition 5.1.3 Operating System Concerns 5.1. 4 Process Interaction 5.1.5 Requirements for Mutual Exclusion
5.1 Principles of Concurrency • 5.1.0 What is concurrency • 5.1.1 A Simple Example • 5.1.2 Race Condition • 5.1.3 Operating System Concerns • 5.1.4 Process Interaction • 5.1.5 Requirements for Mutual Exclusion 14
5.1.2 Race Condition (1/1) Race condition(竞争条件) A race condition occurs when multiple processes or threads read and write data Items The final result depends on the order of execution The loser of the race is the process that updates last and will determine the final value of the variable 15
15 5.1.2 Race Condition(1/1) • Race Condition(竞争条件) • A race condition occurs when multiple processes or threads read and write data items • The final result depends on the order of execution • The “loser”of the race is the process that updates last and will determine the final value of the variable
5.1 Principles of concurrent 5.1.0 What is concurrency .5.1.1 A Simple example ·5.1.2 Race condition .5.1.3 Operating system Concerns 5.1. 4 Process Interaction 5.1.5 Requirements for Mutual Exclusion
5.1 Principles of Concurrency • 5.1.0 What is concurrency • 5.1.1 A Simple Example • 5.1.2 Race Condition • 5.1.3 Operating System Concerns • 5.1.4 Process Interaction • 5.1.5 Requirements for Mutual Exclusion 16