Concurrency

Multiple programs running, or appearing to run at the same time

Parallelism

Example

A company hires 90 workers to make 90 widgets and have them work in parallel

  • It takes 1 worker 10 months to make 1 widget
  • Latency for first widget can be >> 1/10 month
    • Throughput may be < 10 widgets per month
    • If no perfectly parallelized

100 workers making 10,000 widgets may achieve > 10 widgets / month

  • if for part of the process they have to wait for some subtask to complete

Preemptive Multitasking

Critical Section

Solution

Atomic instructions

  • Use processor features to make it look like you made the update instantaneously

Locks

  • Prevent concurrent execution of certain instruction by different threads
Sometimes we allow for race conditions

Provides greater efficiency

  • number of hits on a website
  • more concerned with speed than accuracy

Detecting data races

Sequential Consistency

x86 Consistency

x86 Atomicity

Mutex

Condition Variables

Monitors

Semaphores