Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this project, you are asked to write two independent programs, thr.c and proc.c, which use threads and processes to concurrently compute the sum of

image text in transcribed

In this project, you are asked to write two independent programs, thr.c and proc.c, which use threads and processes to concurrently compute the sum of squareroot s 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 squareroot s from 1 to n/3, while the two child threads computes the sum of the squareroot s 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 squareroot s: 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 squareroot s. 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. In this project, you are asked to write two independent programs, thr.c and proc.c, which use threads and processes to concurrently compute the sum of squareroot s 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 squareroot s from 1 to n/3, while the two child threads computes the sum of the squareroot s 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 squareroot s: 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 squareroot s. 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

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

Step: 3

blur-text-image

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

Intelligent Databases Technologies And Applications

Authors: Zongmin Ma

1st Edition

1599041219, 978-1599041216

More Books

Students also viewed these Databases questions

Question

What is DDL?

Answered: 1 week ago