AdminDev Labs

Researching Systems Engineering and Computer Science


Latest Episode


Race Conditions

Definition

Tanenbaum example (Printer daemon)

Golang example (Incrementing a counter)

Go-isms

Avoiding Race Conditions

Mutal Exclusion

#define FALSE     0
#define TRUE     1
#define N    2             / * number of processes * /
int turn;                / * whose turn is it? * /
int interested[N];             / * all values initially 0 (FALSE) * /

void enter region(int process);        / * process is 0 or 1 * /
{

    int other;             / * number of the other process * /

    other = 1process;        / * the opposite of process * /
    interested[process] = TRUE;    / * show that you are interested * /
    turn = process;            / * set flag * /
    while (turn == process && interested[other] == TRUE) / * null statement * / ;
}

void leave region(int process)        / * process: who is leaving * /
{
    interested[process] = FALSE;    / * indicate departure from critical region * /
}

Episode List

AdminDev Labs