Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include #include #include #define NUM_Threads 10 int globalVar void *executeThreadFunc(void *args) { long threadID = (long)args; int i,j; for(i=0;i <10;i++){ for( j=0;j <100;j++) {

#include

#include

#include

#include

#define NUM_Threads 10

int globalVar

void *executeThreadFunc(void *args)

{

long threadID = (long)args;

int i,j;

for(i=0;i<10;i++){

for( j=0;j<100;j++)

{

thead.sleep(100);

}}

pthread_exit(NULL);

}

int main()

{

pthread_t nThreads[NUM_Threads];

long i, status;

int r;

r=thread.getid();

if(r%2==0)

{

globalVar++;

}

else

{

globalVar--;

}

for(i=0;i

status=pthread_create(&nThreads[i], NULL, executeThreadFunc, (void *) i);

if(status>0)

{

print( Error Creating Thread);

return 1;

}

}

print(r);

Return 0;

}

1. When it starts the execution, print the ID of the current thread being executed. For example - Thread 1 Started Execution

2. When it ends the execution, print the ID of the current thread being ended. For example - Thread 1 Ended Execution

3. What is the expected order of thread execution? Provide the expected order with thread numbers. what is the expected value of globalVar after the last thread finishes execution? show calculation for globalVar.

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

Fundamentals Of Database System

Authors: Elmasri Ramez And Navathe Shamkant

7th Edition

978-9332582705

More Books

Students also viewed these Databases questions