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 />

/* In the following _incorrect_ version of the producer we reverse */<br />

/* the order of down call on the semaphores. */<br />

/* This will cause DEADLOCK if the buffer is full … Why? */<br />

void producer(void)<br />

{<br />

int item;<br />

}<br />

while (TRUE) { /* repeat forever */<br />

produce_item(&item); /* generate next item */<br />

down(&mutex); /* enter critical region */<br />

down(&empty); /* decrement empty count */<br />

enter_item(item); /* put item in buffer */<br />

up(&mutex); /* leave critical region */<br />

up(&full); /* increment count of full slots */<br />

Copyright © 2007 <strong>David</strong> <strong>Vernon</strong> (www.vernon.eu)

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

Saved successfully!

Ooh no, something went wrong!