Mutual Exclusion Based on Message Passing

Inter-Process Communication

Posted on Updated on

Mutual Exclusion Based on Message Passing

clip_image002

Mutual Exclusion Based on Message Passing Code

P1:

send(Resource Contro, “Give me resource”);

receive(Resource Controller, Message);

// block while waiting for a reply from RC

{

…Critical Section…

}

send(Resource Controller, “Done with resource”);

Bounded Buffer Problem (no shared memory)

clip_image004

void consumer(void)

int item;

message m;

// initialization loop

for (i=0; i<N; i++) send(producer, &m);// N empty slots

while (TRUE) {

receive(producer, &m); // receive item

item=extract_item(&m);

send(producer, &m); // send empty slot

consume_item(item);

}

clip_image006

void producer(void)

int item;

message m;

while (TRUE) {

item Produce_Item();

receive(consumer, &m); // empty slot

build_message(&m, item);

send(consumer, &m); // send item

}

Posted By-: Vissicomp Technology Pvt. Ltd.

Website -: http://www.vissicomp.com

Advertisements