Lecture 8: Intro to Concurrency

Introduction

Concurrent vs parallel

  1. Concurrent = happening at at the same time, interleaving, sharing resources
  2. Parallel = happening at the same time, progressing independently

In a modern OS: concurrency is everywhere

Approaches

  1. Process-Based
  2. Event-Based
  3. Thread-based

Concurrency with Threads

Using Threads

Concurrency Problems

  1. Data race - what we saw with sum
  2. Deadlock - we’ll see examples later
  3. Starvation

Data Races

Aside: When is data shared?

  1. Global variables
  2. Local variables
  3. Local static variables

Fixing Data Races

Mutexes

Semaphores

Locking problems: Deadlocks

Avoiding locking