Question: Note: Please answer the questions briefly. Do not give long, winding, irrelevant answers. 1. Making water. This problem is simulating the process of hooking up

 Note: Please answer the questions briefly. Do not give long, winding,

Note: Please answer the questions briefly. Do not give long, winding, irrelevant answers. 1. Making water. This problem is simulating the process of hooking up hydrogen atoms with oxygen atoms to form water molecules. Each atom is represented by a separate thread. We will need to associate two hydrogen threads with one oxygen thread to make a water molecule, then all three threads exit together. We will use two general semaphores, one to count the number of hydrogen threads and one for the number of oxygen threads. Please use Pthread for multi-threading and Pthread semaphores for synchronization. (3 pts) sem_t oxygen, hydrogen; // two Pthread semaphores int main(int argc, char* argv[]) { //fill in your code to initialize two semaphores using sem_init() int num_of_water = atoi(argv[1]); //# of water molecules pthread_t tidox[num_of_water), tidhydro[2*num_of_water); //create hydrogen atom threads for (int k = 0; k

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!