Question: Multithreaded C program using the Pthreads API ( Use Ubuntu ( Linux ) ) Create, compile, and execute a C program to demonstrate the basic
Multithreaded C program using the Pthreads API Use Ubuntu Linux
Create, compile, and execute a C program to demonstrate the basic Pthreads API for constructing a multithreaded program that calculates the summation of a nonnegative integer in a separate thread. When this program begins, a single thread of control begins in main After some initialization, main creates a second thread that begins control in the runner function. Refer Fig Multithreaded C program using the Pthreads API. You need to add #include to include the standard library to avoid implicit declaration of function atoi warning.
Note: Verify if all underscores are present. All pthread functions begin with pthread
To compile a program called multithread.c:
gcc multithread.c pthread o multithread
The sample program calculates the summation of the integer parameter provided on the command line. To compute summation of numbers to execute:
multithread
For full points, submit before due time : pm PST
Pthreads:
#include
#include
#include
int sum;
void runnervoid param
int i upper atoichar param;
sum ;
for i ; i upper; i
sum i;
pthreadexit;
int mainint argc, char argv
pthreadt tid;
pthreadattrt attr;
pthreadattrinit&attr;
pthreadcreate&tid, &attr, runner, argv;
pthreadjointid NULL;
printfsum d
sum;
return ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
