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

10
1 Interprocess Communication Race Conditions Two processes want to access shared memory at same time
  • date post

    22-Dec-2015
  • Category

    Documents

  • view

    213
  • download

    0

Transcript of 1 Interprocess Communication Race Conditions Two processes want to access shared memory at same...

1

Interprocess CommunicationRace Conditions

Two processes want to access shared memory at same time

2

Critical Regions (1)

Four conditions to provide mutual exclusion1. No two processes simultaneously in critical region

2. No assumptions made about speeds or numbers of CPUs

3. No process running outside its critical region may block another process

4. No process must wait forever to enter its critical region

3

Critical Regions (2)

Mutual exclusion using critical regions

4

Mutual Exclusion with Busy Waiting (1)

Proposed solution to critical region problem(a) Process 0. (b) Process 1.

5

Mutual Exclusion with Busy Waiting (2)

Peterson's solution for achieving mutual exclusion

6

Mutual Exclusion with Busy Waiting (3)

Entering and leaving a critical region using the

TSL instruction

7

Sleep and Wakeup

Producer-consumer problem with fatal race condition

8

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.

9

Semaphores

The producer-consumer problem using semaphores

10

Mutexes

Implementation of mutex_lock and mutex_unlock