Read Sections 8.1 PUP
Last time we discussed two software solutions to the critical section problem that didn't work. In this lecture we will talk about solutions that do work.
int flag[2] = {0, 0}; /* shared variable */ int turn = 0; /* shared variable */ PROCESS 0: PROCESS 1: while(1) { while(1){ flag[0] = 1; flag[1] = 1; turn = 1; turn = 0; while (flag[1] && turn = 1); while (flag[0] && turn == 0);flag[0] = 0; flag[1] = 0; } }
test-and-set
(Example 8.5 of PUP)
swap
Skill: Understand software and hardware locking mechanisms.