Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

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

The Database Relational Model A Retrospective Review And Analysis

Authors: C. J. Date

1st Edition

0201612941, 978-0201612943

More Books

Students also viewed these Databases questions

Question

What is the difference between Needs and GAP Analyses?

Answered: 1 week ago

Question

What are ERP suites? Are HCMSs part of ERPs?

Answered: 1 week ago