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

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

Advances In Databases And Information Systems 14th East European Conference Adbis 2010 Novi Sad Serbia September 2010 Proceedings Lncs 6295

Authors: Barbara Catania ,Mirjana Ivanovic ,Bernhard Thalheim

2010th Edition

3642155758, 978-3642155758

Students also viewed these Databases questions