Question: Need help writing a program in C called thr.c and proc.c, which use threads and processes to concurrently compute the sum of square roots from

Need help writing a program in C called thr.c and proc.c, which use threads and processes to concurrently compute the sum of square roots from 1 to n, where n is a multiple of 3 and is specified in the command line.

For the program thr.c, it gets the value n from the command line argument and converts it to an integer Next, it creates two threads using pthread_createl). Then, the main thread computes the sum of square roots from 1 to n/3, while the two child threads computes the sum of the square roots from n/3+1 to2n/3 and 2n/3+1 to n, respectively. All three partial sums should be added together to a shared global variable The main thread calls pthread_join() to wait for the termination of the two child threads and then prints the result. Below is an example of running your thread program: spirits thr 9999 sum of square roots: 666616.459197 The program proc.c is similar to thr.c except that you need to use processes instead of threads. That is, your program should set up two pipes and then call the function fork() to create two child processes. Each of the parent and the two child processes computes its own partial sum of the square roots. To collect the three partial sums, the first child process should write its result to a pipe. The second process reads the value forwarded by the first child, adds its result, and then forward it to the parent through another pipe The parent gets the value from the second pipe, adds it with its partial sum, and prints the result.

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!