



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The code and explanation of two common interprocess synchronization and communication methods: producer/consumer implementation with a shared buffer and message passing. The producer/consumer implementation uses a shared buffer and a counter to ensure proper synchronization between producing and consuming processes. Message passing uses the send and receive functions to enable communication and synchronization between processes.
Typology: Study notes
1 / 6
This page cannot be seen from the preview
Don't miss anything!




1
processProducer varc : char begin loop < produce a character “c” > whilenextIn+1 modn =nextOut do NOOP end while buf[nextIn] :=c nextIn :=nextIn+ 1 modn end loop end Producer
processConsumer varc : char begin loop whilenextIn =nextOut do NOOP end while c :=buf[nextOut] nextOut :=nextOut+1 modn < consume a character “c” > end loop endConsumer
globals buf : array [0..n-1] of char; n-1 nextIn,nextOut :0..n-1 := 0 n-
3
processProducer varc : char begin loop < produce a character “c” > whilecount =n do NOOP end while buf[nextIn] :=c nextIn :=nextIn+ 1 modn count :=count + 1 end loop end Producer
processConsumer varc : char begin loop whilecount = 0 do NOOP end while c :=buf[nextOut] nextOut :=nextOut+1 mod n count :=count - 1 < consume a character “c” > end loop endConsumer
globals buf : array [0..n-1] of char; nextIn,nextOut : 0..n-1 := 0 count : integer := 0
n- n-
7
process producer begin loop < produce a char “c” > send(consumer, c) end loop end producer
process consumer begin loop receive(producer,mesg) < consume message “mesg” > end loop end consumer
9