Question: C programming, threads Scenario: Threads Using pthreads, implement a program that compute the summation of 0.ta Max (inclusive). Yous program should distribute the work evenly

C programming, threads

C programming, threads Scenario: Threads Using pthreads, implement a program that compute

Scenario: Threads Using pthreads, implement a program that compute the summation of 0.ta Max (inclusive). Yous program should distribute the work evenly over a number of threads defined as THREAD_COUNT Useful Functions Linux Description int pthread attr initipthread attrtattr initialize and destroy thread attributes create a new th int pthread_create(pthread_t thread, const pthread_attr t "attr, void *(*start_ routine) (void *) void arg): int pthre join with a terminated thread terminate calling thread pt , void 'ret void pthread exit void 'retval) (a) Finish implementing the main function: [4 points) #includ- #include define THEAD CUT 4 int max; int result [THREAD COUNT]: //global to store partial sums from threads void sunne.(void .pazam); //fo.ward declaration /umber of threads //global to stose the numbe: of elements to sum int main (int arge, char argv Il) int sum0; //assume result has all entries set to 0 pth:esd_t tid [THREAD COUNT] pthread attr_t attr max atoi ( argv [ 1 ] ) pthread attr_init(&attr): printf("sum %d ", sum ) ; (b) Finish implementing runner. An thread of runner should be created when the program wants to take a partial sum. param should be the thread number (0 to THREAD_COUNT-1) Each thread (id) should compute the appropriate partial sum and store it in result/id). (4 points] void runner (void *param) //Hint: max and result will be usable int id-(int) param; 6 Scenario: Threads Using pthreads, implement a program that compute the summation of 0.ta Max (inclusive). Yous program should distribute the work evenly over a number of threads defined as THREAD_COUNT Useful Functions Linux Description int pthread attr initipthread attrtattr initialize and destroy thread attributes create a new th int pthread_create(pthread_t thread, const pthread_attr t "attr, void *(*start_ routine) (void *) void arg): int pthre join with a terminated thread terminate calling thread pt , void 'ret void pthread exit void 'retval) (a) Finish implementing the main function: [4 points) #includ- #include define THEAD CUT 4 int max; int result [THREAD COUNT]: //global to store partial sums from threads void sunne.(void .pazam); //fo.ward declaration /umber of threads //global to stose the numbe: of elements to sum int main (int arge, char argv Il) int sum0; //assume result has all entries set to 0 pth:esd_t tid [THREAD COUNT] pthread attr_t attr max atoi ( argv [ 1 ] ) pthread attr_init(&attr): printf("sum %d ", sum ) ; (b) Finish implementing runner. An thread of runner should be created when the program wants to take a partial sum. param should be the thread number (0 to THREAD_COUNT-1) Each thread (id) should compute the appropriate partial sum and store it in result/id). (4 points] void runner (void *param) //Hint: max and result will be usable int id-(int) param; 6

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!