Synchronization 1: Atomicity

Overview

In this lecture, we discuss multithreading, low-level synchronization, and synchronization objects.

Multitasking, multiprocessing, multithreading

Creating and joining threads in C++

A toy task

incr-basic.cc

What?!

incr-basic-noopt

Data races

The Fundamental Law of Synchronization

THOU SHALT NOT HAVE DATA RACES!!!

Atomic operations

addl $0x1,(%rdi)

Atomic instructions

incr-atomic.cc

Mutual exclusion

std::mutex

incr-mutex.cc

std::scoped_lock

Question

incr-spinlock.cc

Spinning vs. blocking

Minipipe