Question: Synchronization problem (use locks and condition variables) You have been hired by a company to work on a program that does climate modelling. The inner
Synchronization problem (use locks and condition variables)

You have been hired by a company to work on a program that does climate modelling. The inner loop of the program matches atoms of different types as they form molecules. In an excessive reliance on threads, each atom is represented by a thread. A Your task is to write code to form carbon dioxide out of one carbon thread and two oxygen threads (CO2). You are to write the two procedures: CArrives () and OArrives (). A carbon dioxide molecule forms when two O threads are present and one C thread; otherwise the atoms must wait. Once all three are present, one of the threads calls MakeCO2(). and only then, all three depart. Extending the product line into beer production, your task is to write code to form alcohol (C2H60) out of two carbon atoms, six hydrogens, and one oxygen. You must use locks and Mesa-style condition variables to implement your solutions. Obviously, an atom that arrives after the molecule is made must wait for a different group of atoms to be present. There should be no busy-waiting. There should also be no useless waiting: atoms should not wait if there is a sufficient number of each type to make a particular molecule. You have been hired by a company to work on a program that does climate modelling. The inner loop of the program matches atoms of different types as they form molecules. In an excessive reliance on threads, each atom is represented by a thread. A Your task is to write code to form carbon dioxide out of one carbon thread and two oxygen threads (CO2). You are to write the two procedures: CArrives () and OArrives (). A carbon dioxide molecule forms when two O threads are present and one C thread; otherwise the atoms must wait. Once all three are present, one of the threads calls MakeCO2(). and only then, all three depart. Extending the product line into beer production, your task is to write code to form alcohol (C2H60) out of two carbon atoms, six hydrogens, and one oxygen. You must use locks and Mesa-style condition variables to implement your solutions. Obviously, an atom that arrives after the molecule is made must wait for a different group of atoms to be present. There should be no busy-waiting. There should also be no useless waiting: atoms should not wait if there is a sufficient number of each type to make a particular molecule
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
