#include #include int product;/ this data is shared by the thread (s) */ void *runner (void *param); /* threads call t

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

#include #include int product;/ this data is shared by the thread (s) */ void *runner (void *param); /* threads call t

Post by answerhappygod »

Include Include Int Product This Data Is Shared By The Thread S Void Runner Void Param Threads Call T 1
Include Include Int Product This Data Is Shared By The Thread S Void Runner Void Param Threads Call T 1 (66.99 KiB) Viewed 17 times
#include #include int product;/ this data is shared by the thread (s) */ void *runner (void *param); /* threads call this function +/ typedef struct{ / data structure for passing data to threads */ int start; int end; ) parameters; int main(int argc, char *argv[]) { pthread_t workerl, worker2; product=1; parameters *data = (parameters *) malloc(sizeof (parameters)); data->start = 5; data->end = 10; pthread_create (&workerl, NULL, runner, data); data (parameters *) malloc (sizeof (parameters)); data->start = 11; data->end = 16; pthread_create (&worker2, NULL, runner, data); = pthread_join (workerl, NULL); pthread_join (worker2, NULL); printf("result- %d\n", product); return 0; } void *runner (void *params) { parameters* p = (parameters *)params; for (int i= p->start; i <= p->end; i++) product *= i; pthread_exit(0);
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply