Question: Please use C + + langague , Please do not motify the code, just fix totalsum make the result Correctly. #include #include pthread.h #include
Please use ClangaguePlease do not motify the code, just fix totalsum
make the result Correctly.
#include
#include "pthread.h
#include
#include
using namespace std;
to protect the CS
pthreadmutext Countmutex PTHREADMUTEXINITIALIZER;
double totalsum ;
function to calculate
double factorailint num
double fact ;
forint i ; i num; i
fact i;
cout "Factorial i "end; i
partsum factoraili;
pthreadmutexlock&Countmutex;
totalsum partsum;
pthreadmutexunlock&Countmutex;
return nullptr;
int main
get the num from user
int n;
cout "Enter the value of n max number in the series: ;
cin n;
divide it so it's works between threads
int mid n ;
Create threads
ThreadArgs arg new ThreadArgsmid;
ThreadArgs arg new ThreadArgsmidn;
pthreadt tidtid;
pthreadcreate&tidnullptr,series,arg;
pthreadcreate&tidnullptr,series,arg;
pthreadjointidnullptr;
pthreadjointidnullptr;
Print the sequence and total result
cout "Sequence: ;
for int i ; i n; i
cout i ;
if i n cout ;
cout endl;
cout "Total Result: totalsum endl;
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
