30.10.2014 Views

Operating Systems - David Vernon

Operating Systems - David Vernon

Operating Systems - David Vernon

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Processes<br />

#include “prototypes.h”<br />

#define FALSE 0<br />

#define TRUE 1<br />

#define N 2 /* number of processes */<br />

int turn; /* global variable: who’s turn is it */<br />

int interested[N]; /* all values initally 0 (FALSE) */<br />

void enter_region(int process) /* process: who is entering (0 or 1) */<br />

{<br />

int other; /* id number of the other process */<br />

}<br />

other = 1 - process; /* set it to the other (of 2) processes *<br />

interested[process] = TRUE; /* record interest in entering region *<br />

turn = process; /* set flag *<br />

while (turn == process && interested[other] == TRUE) ; /* wait */<br />

void leave_region(int process) /* process: who is leaving (0 or 1) */<br />

{<br />

interested[process] = FALSE;/* indicate departure */<br />

} Copyright © 2007 /* <strong>David</strong> from <strong>Vernon</strong> (www.vernon.eu) critical region */

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!