Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C code help please! Use the following C code as the base source code and edit based on questions 1. Declare one global variable of

C code help please!

Use the following C code as the base source code and edit based on questions

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

#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; }

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

Introductory Relational Database Design For Business With Microsoft Access

Authors: Jonathan Eckstein, Bonnie R. Schultz

1st Edition

1119329418, 978-1119329411

More Books

Students also viewed these Databases questions

Question

Define subconscious/implicit bias AppendixLO1

Answered: 1 week ago