Lesson 14: Concurrency & Parallelism


Imagine this setup code:

zero: int = const 0;
one: int = const 1;
a: ptr<int> = alloc one;
b: ptr<int> = alloc one;
store a zero;
store b zero;

that stores 0 in two pointers, a and b. Then imagine these two threads running concurrently:

# thread 1
store a one;
bv: int = load b;

# thread 2
store b one;
av: int = load a;

What are the possible values of av and bv at the end? If you said the set {(0, 1), (1, 0), (1, 1)}, then you’re implicitly imagining that parallel execution looks like an interleaving of the instructions from parallel threads. That would be nice! It’s a memory model called sequential consistency. (For more on memory models, I strongly recommend a primer by Sorin, Hill, and Wood.)


There are no tasks for this lesson other than pondering the deep weirdness of programming with shared-memory multithreading. Good luck on your course project!

This is the last lesson of CS 6120. If you’re taking the self-guided version of the course, please fill out this feedback form. I would love to know who has taken the class—and I want your opinions about how to make it better!