Processes 3: Interruption and race conditions

Overview

In this lecture, we discuss the Unix analogue of kernel interrupts, namely signals, and race conditions. This is a bridge lecture to the synchronization unit.

Full lecture notesTextbook readings

The simple life

Life before synchronization

Multitasking

Life after synchronization

Race conditions

Example: Relay race

Relay race attempt 1

$ /bin/echo Handoff | grep H

Successful relay handoff

https://www.thestar.com/sports/olympics/2016/08/18/why-the-us-womens-4x100-relay-team-ran-by-themselves-on-the-track.html

Relay race attempt 2

$ /bin/echo Handoff > handoff.txt & grep H handoff.txt

Unsuccessful relay handoff

https://www.dailymail.co.uk/sport/olympics/article-2185586/London-Olympics-2012-Great-Britain-looking-overcome-baton-woes-relays.html

Unsuccessful relay handoff

https://www.stabroeknews.com/2016/08/19/sports/u-s-grasp-second-chance-4x100-relay/

Explanation

Reasoning about race conditions

Signals

Signal system calls

void handle_signal(int signal_number) {
    // do something to handle the signal
}

...
struct sigaction sa;
sa.sa_handler = handle_signal; // or SIG_IGN or SIG_DFL
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
sigaction(SIGINT, &sa, nullptr);

When can a signal be delivered?

Racer

racer-poll

Racer arguments

Polling and blocking

racer-block

racer-blockvar

Race conditions!

racer-selfpipe