Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CGS3763 - Semaphore / Mutex Code Explanation You will need to explain step by step what is happening in the program. Please use paragraph writing

CGS3763 - Semaphore / Mutex Code Explanation You will need to explain step by step what is happening in the program. Please use paragraph writing in a Word document.

//HW1

semaphore full; semaphore empty; binarysem mutex; int bucket[5]; int i=0; int j=0; int count=0;

void producer() { int k; for(k=0;k<20;k++) { p(full); //decrement 1 p(mutex); bucket[i]=count++; //produces item cout<<"Item "<< bucket[i]<<" produced."< i=(i+1)%5; v(mutex);//increment v(empty); } }

void consumer() { int x; for(x=0;x<20;x++) { p(empty);//decrement 1 p(mutex);

cout<<"Item "<

v(mutex); v(full);//increment 1 } }

void main() { //initialize initialsem(mutex,1); initialsem(full,5); initialsem(empty,0);

cobegin { producer(); consumer(); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database Technology

Authors: Suad Alagic

1st Edition

354096276X, 978-3540962762

More Books

Students also viewed these Databases questions

Question

Which team solution is more likely to be pursued and why?

Answered: 1 week ago

Question

4. I can tell when team members dont mean what they say.

Answered: 1 week ago