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

/*** producer-consumer solution with message passing ***/<br />

#include “prototypes.h”<br />

#define N 100 /* number of slots in the buffer */<br />

#define MSIZE 4 /* message size */<br />

typedef int message[MSIZE]<br />

void producer(void)<br />

{<br />

int item;<br />

message m; /* message buffer */<br />

}<br />

while (TRUE) {<br />

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

receive(consumer, &m); /* wait for an empty to arrive */<br />

build_message(&m, item); /* construct a message to send */<br />

send(consumer, &m); /* send item to consumer */<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!