Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

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

Students also viewed these Databases questions