Question: code in C Thread synchronization using semaphores: The H20 problem: You've been hired by Mother Nature to help with the chemical reaction to form water,

 code in C Thread synchronization using semaphores: The "H20" problem: You've

code in C

Thread synchronization using semaphores: The "H20" problem: You've been hired by Mother Nature to help with the chemical reaction to form water, which she doesn't seem to be able to get right due to synchronization problems. The trick is to get two H atoms and one O atom all together at the same time. The atoms are threads. Each H atom thread executes a procedure hReady () when it is ready to react, and each O atom thread invokes a procedure oReady () when it is ready. Your job is to write the code for hReady () and oReady (). The procedures must delay until there are at least two H atoms and one O atom present, and then one of the procedures must call the procedure makeWater (). After the makeWater () call, two instances of hReady () and one instance of oReady() should return. Your solution should avoid starvation and busy-waiting. You may assume that the semaphore implementation enforces the FIFO policy for thread wake-ups - the thread waiting the longest in wait() always grabs the semaphore after a signal()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!