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 N 100 /* number of slots in the buffer */<br />

int count = 0; /* number of items in the buffer */<br />

void producer(void)<br />

{<br />

int item;<br />

}<br />

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

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

if (count == N) sleep(); /* if buffer is full, go to sleep */<br />

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

count = count + 1; /* increment count of items in buffer */<br />

if (count == 1) wakeup(consumer) /* was buffer empty */<br />

}<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!