Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Sara, Mohammed, and Abdullah make coffee perfectly. Sara grinds coffee and put them in capsules. Mohammed then places the coffee capsule in a coffee machine.

image text in transcribed

Sara, Mohammed, and Abdullah make coffee perfectly. Sara grinds coffee and put them in capsules. Mohammed then places the coffee capsule in a coffee machine. Abdullah then serves the coffee that is done by the coffee machine. There are several synchronization constraints:

1. Mohammed cannot make a coffee unless at least one coffee capsule exists, but Mohammed does not care how far Sara gets ahead of him.

2. Abdullah cannot serve a coffee unless at least one capsule exists in which Mohammed has used in a machine to make a coffee, and the coffee has not yet been served. Abdullah does not care how far Mohammed gets ahead of him.

3. Mohammed does care that Sara does not get more than MAX capsules ahead of him. Thus, if there are MAX coffee capsules, Sara has to wait. 4. There is only one coffee machine with which both Sara and Mohammed need to prepare and use the coffee capsules, respectively. Write a multithreaded program with three threads which represent Sara, Mohammed and Abdullah using semaphores as the synchronization mechanism.

Hint : No need to provide detailed implementation regarding operations bellow:

prepare_capsule(); // Saras operation

make_coffee(); // Muhammads operation

serve_coffee(); // Abdullahs operation

You can implement them as printf() statements

***** Can you solve this correctly because I asked the same question and the answer was wrong in c language

Problem 2: Sara, Mohammed, and Abdullah make coffee perfectly. Sara grinds coffee and put them in capsules. Mohammed then places the coffee capsule in a coffee machine. Abdullah then serves the coffee that is done by the coffee machine. There are several synchronization constraints: 1. Mohammed cannot make a coffee unless at least one coffee capsule exists, but Mohammed does not care how far Sara gets ahead of him. 2. Abdullah cannot serve a coffee unless at least one capsule exists in which Mohammed has used in a machine to make a coffee, and the coffee has not yet been served. Abdullah does not care how far Mohammed gets ahead of him. 3. Mohammed does care that Sara does not get more than MAX capsules ahead of him. Thus, if there are MAX coffee capsules, Sara has to wait. 4. There is only one coffee machine with which both Sara and Mohammed need to prepare and use the coffee capsules, respectively. Write a multithreaded program with three threads which represent Sara, Mohammed and Abdullah using semaphores as the synchronization mechanism. Hint : No need to provide detailed implementation regarding operations bellow: prepare_capsule(); // Sara's operation make coffee (); // Muhammad's operation serve_coffee (); // Abdullah's operation . . You can implement them as printf() statements

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_2

Step: 3

blur-text-image_3

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

Sams Teach Yourself Beginning Databases In 24 Hours

Authors: Ryan Stephens, Ron Plew

1st Edition

067232492X, 978-0672324925

More Books

Students also viewed these Databases questions