Question
C code help please! Use the following C code as the base source code and edit based on questions #include #include #include #include #define NUM_Threads
C code help please!
Use the following C code as the base source code and edit based on questions
#include #include #include #include
#define NUM_Threads 10
void *executeThreadFunc(void *args) { long threadID = (long)args; int i,j;
for(i=0;i<10;i++) for(j=0;j<100;j++) pthread_exit(NULL); }
int main() { pthread_t nThreads[NUM_Threads]; long i, status; for(i=0;i { status=pthread_create(&nThreads[i], NULL, executeThreadFunc, (void *) i); if (status>0) { printf(" Error Creating Thread"); return 1; } }
for(i=0;i { pthread_join(nThreads[i], NULL); } return 0; }
1. Declare one global variable of type integer. For example, int globalVar.
2. You will find the function named void *executeThreadFunc(void *args) in the source code. In this method do the following:
a. When it starts the execution, print the ID of the current thread being executed. For example - Thread 1 Started Execution
b. Next, check the ID of Thread i. If the ID is an even number, then increment the globalVar by 1[1] ii. If the ID is an odd number, then decrement the globalVar by 1
c. When it ends the execution, print the ID of the current thread being ended. For example - Thread 1 Ended Execution
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started