Ch2b-IPC - 1 Chapter 2 (Second Part) Slide Credits:...

Info iconThis preview shows pages 1–25. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 Chapter 2 (Second Part) Slide Credits: Jonathan Walpole Andrew Tanenbaum Interprocess Communication and Synchronization 2 Outline Race Conditions Mutual Exclusion and Critical Regions Mutex Locks Test-And-Set Instruction Sleep, Yield, Wakeup Disabling Interrupts in the Kernel Classical IPC Problems: Producer-Consumer Readers-Writers Dining Philosophers Sleeping Barber 3 Multiple Processes will Cooperate Assumptions: Two or more threads (or processes) Each executes in (pseudo) parallel Cannot predict exact running speeds The threads can interact Example: Access to a shared variable Example: One thread writes a variable The other thread reads from the same variable Problem: The order of READs and WRITEs can make a difference!!! 4 Race Condition: An Example Incrementing a counter (load, increment, store) Context switch can occur after load and before increment! 5 Race Conditions Whenever the output depends on the precise execution order of the processes!!! Why do race conditions occur? values of memory locations replicated in registers during execution context switches at arbitrary times during execution threads can see stale memory values in registers What solutions can we apply? prevent context switches by preventing interrupts make threads coordinate with each other to ensure mutual exclusion in accessing critical sections of code 6 Mutual Exclusion Critical Region (Critical Section): The part of the code accessing shared data Desired Conditions: (1) No two threads simultaneously in critical region. (2) No assumptions made about speeds or numbers of CPUs. (3) No thread running outside its critical region may block another thread. (4) No thread must wait forever to enter its critical region (no starvation ). 7 Critical regions with mutual exclusion 8 How can we enforce mutual exclusion? What about using a binary lock variable in memory and having threads check it and set it before entry to critical regions? Solves the problem of exclusive access to shared data. Expresses intention to enter Critical Section Acquiring a lock prevents concurrent access Assumptions: Every threads sets lock before accessing shared data! Every threads releases the lock after it is done! 9 Acquiring and Releasing Locks Free Lock Thread A Thread D Thread C Thread B 10 Acquiring and Releasing Locks Free Lock Thread A Thread D Thread C Thread B Lock 11 Acquiring and Releasing Locks Set Lock Thread A Thread D Thread C Thread B Lock 12 Acquiring and Releasing Locks Set Lock Thread A Thread D Thread C Thread B Lock 13 Acquiring and Releasing Locks Set Lock Thread A Thread D Thread C Thread B 14 Acquiring and Releasing Locks Set Lock Thread A Thread D Thread C Thread B Lock 15 Acquiring and Releasing Locks Set Lock Thread A Thread D Thread C Thread B Lock 16 Acquiring and Releasing Locks Set Lock Thread A Thread D Thread C Thread B Lock Lock Lock 17 Acquiring and Releasing Locks Set Lock Thread A Thread D Thread C Thread B Lock Lock Lock 18 Acquiring and Releasing Locks Set Lock Thread A Thread D Thread C Thread B Lock Lock Lock Unlock 19 Acquiring and Releasing Locks Set Lock Thread A Thread D Thread C Thread B Lock Lock Lock Unlock 20 Acquiring and Releasing Locks Free Lock Thread A Thread D Thread C Thread B Lock Lock Lock 21 Acquiring and Releasing Locks Free Lock Thread A Thread D Thread C Thread B Lock Lock Lock 22 Acquiring and Releasing Locks Set Lock Thread A Thread D Thread C Thread B Lock Lock Lock 23 Acquiring and Releasing Locks Set Lock Thread A Thread D Thread C Thread B Lock Lock Lock 24 Acquiring and Releasing Locks Set Lock Thread A Thread D Thread C Thread B Lock Lock 25...
View Full Document

This note was uploaded on 01/18/2012 for the course INFORMATIK 2011 taught by Professor Phanthuongcang during the Winter '11 term at Cornell University (Engineering School).

Page1 / 80

Ch2b-IPC - 1 Chapter 2 (Second Part) Slide Credits:...

This preview shows document pages 1 - 25. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online