Interprocess Communication Race Conditions Two processes want to

  • Slides: 10
Download presentation
Interprocess Communication Race Conditions Two processes want to access shared memory at same time

Interprocess Communication Race Conditions Two processes want to access shared memory at same time 1

Critical Regions (1) Four conditions to provide mutual exclusion 1. 2. 3. 4. No

Critical Regions (1) Four conditions to provide mutual exclusion 1. 2. 3. 4. No two processes simultaneously in critical region No assumptions made about speeds or numbers of CPUs No process running outside its critical region may block another process No process must wait forever to enter its critical region 2

Critical Regions (2) Mutual exclusion using critical regions 3

Critical Regions (2) Mutual exclusion using critical regions 3

Mutual Exclusion with Busy Waiting (1) Proposed solution to critical region problem (a) Process

Mutual Exclusion with Busy Waiting (1) Proposed solution to critical region problem (a) Process 0. (b) Process 1. 4

Mutual Exclusion with Busy Waiting (2) Peterson's solution for achieving mutual exclusion 5

Mutual Exclusion with Busy Waiting (2) Peterson's solution for achieving mutual exclusion 5

Mutual Exclusion with Busy Waiting (3) Entering and leaving a critical region using the

Mutual Exclusion with Busy Waiting (3) Entering and leaving a critical region using the TSL instruction 6

Sleep and Wakeup Producer-consumer problem with fatal race condition 7

Sleep and Wakeup Producer-consumer problem with fatal race condition 7

What is a Semaphore? • A mechanism that provides concurrency among processes. • Facilitates

What is a Semaphore? • A mechanism that provides concurrency among processes. • Facilitates synchronization among processes. • Usually implemented with a struct, including an int as well as other information fields, and a queue to ensure mutual exclusion to a shared resource. • Requires two operations (functions): • sleep() or down() • wakeup() or up() • A new type of variable that saves the number of pending wakeups. 8

Semaphores The producer-consumer problem using semaphores 9

Semaphores The producer-consumer problem using semaphores 9

Mutexes Implementation of mutex_lock and mutex_unlock 10

Mutexes Implementation of mutex_lock and mutex_unlock 10