1 / 8

Concurrent Threads

Initially v=0. Thread 1: for (i=0; i<10; i++) v = v+1;. Thread 2: for (i=0; i<10; i++) v = v-1;. Concurrent Threads. What are the possible values of v at the end?. Mutual Exclusion so far. Four conditions to provide mutual exclusion

fulton-odom
Download Presentation

Concurrent Threads

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Initially v=0. Thread 1: for (i=0; i<10; i++) v = v+1; Thread 2: for (i=0; i<10; i++) v = v-1; Concurrent Threads What are the possible values of v at the end? Cpr E 308, Fall 2003

  2. Mutual Exclusion so far Four conditions to provide mutual exclusion • No two processes simultaneously in critical region • No assumptions made about speeds of CPUs • No process running outside its critical region may block another process • No process must wait forever to enter its critical region Cpr E 308, Fall 2003

  3. Solutions to Mutual Exclusion • Dekker’s Algorithm – 1960’s • Peterson’s Algorithm – 1981 • Hardware support Cpr E 308, Fall 2003

  4. Peterson’s Solution Cpr E 308, Fall 2003

  5. Hardware Support with TSL • Instruction TSL R, LockTSL = “Test and Set Lock”R = register, Lock = memory location • Atomic = “all or nothing” • Atomically- reads Lock into R and - Store a non-zero value into Lock Cpr E 308, Fall 2003

  6. Mutual Exclusion using TSL • Problems: • Busy Waiting, • Not very useful on a uniprocessor Cpr E 308, Fall 2003

  7. Eliminate Busy Waiting Implementation of mutex_lock and mutex_unlock Without busy waiting Cpr E 308, Fall 2003

  8. Producer - Consumer • Producer - Insert produced objects into bounder buffer • Consumer - Delete objects from the buffer and eat them • Synchronization required - Exclusive access to the buffer- Buffer full? - Buffer empty? Cpr E 308, Fall 2003

More Related