Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 2 Processes and Threads 2.3 Interprocess Communication.

Similar presentations


Presentation on theme: "Chapter 2 Processes and Threads 2.3 Interprocess Communication."— Presentation transcript:

1 Chapter 2 Processes and Threads 2.3 Interprocess Communication

2 Figure Two processes want to access shared memory at the same time. Race Conditions Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved

3 Conditions required to avoid race condition: No two processes may be simultaneously inside their critical regions. No assumptions may be made about speeds or the number of CPUs. No process running outside its critical region may block other processes. No process should have to wait forever to enter its critical region. Critical Regions (1) Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved

4 Figure Mutual exclusion using critical regions. Critical Regions (2) Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved

5 Proposals for achieving mutual exclusion: Disabling interrupts Lock variables Strict alternation Peterson's solution The TSL instruction Mutual Exclusion with Busy Waiting Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved

6 Figure A proposed solution to the critical region problem. (a) Process 0. (b) Process 1. In both cases, be sure to note the semicolons terminating the while statements. Strict Alternation Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved

7 Figure Peterson’s solution for achieving mutual exclusion. Peterson's Solution Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved

8 Figure Entering and leaving a critical region using the TSL instruction. The TSL Instruction (1) Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved

9 Figure Entering and leaving a critical region using the XCHG instruction. The TSL Instruction (2) Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved

10 Figure The producer-consumer problem with a fatal race condition. The Producer-Consumer Problem Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved

11 Figure The producer-consumer problem using semaphores. Semaphores Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved

12 Figure Implementation of mutex lock and mutex unlock. Mutexes Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved

13 Figure Some of the Pthreads calls relating to mutexes. Mutexes in Pthreads (1) Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved

14 Figure Some of the Pthreads calls relating to condition variables. Mutexes in Pthreads (2) Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved

15 Figure Using threads to solve the producer-consumer problem. Mutexes in Pthreads (3) Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved

16 Figure A monitor. Monitors (1) Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved

17 Figure An outline of the producer-consumer problem with monitors. Monitors (2) Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved

18 Figure A solution to the producer-consumer problem in Java. Message Passing (1) Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved

19 Figure A solution to the producer-consumer problem in Java. Message Passing (2) Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved

20 Figure A solution to the producer-consumer problem in Java. Message Passing (3) Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved

21 Figure The producer-consumer problem with N messages. Producer-Consumer Problem with Message Passing (1) Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved

22 Figure The producer-consumer problem with N messages. Producer-Consumer Problem with Message Passing (2) Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved

23 Figure Use of a barrier. (a) Processes approaching a barrier. (b) All processes but one blocked at the barrier. (c) When the last process arrives at the barrier, all of them are let through. Barriers Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved


Download ppt "Chapter 2 Processes and Threads 2.3 Interprocess Communication."

Similar presentations


Ads by Google