Question: what does this script display? #include #include #include #define ESC 27 #define NUM_THREADS 20 /*Compile with -pthread*/ void* doSomeThing(void *threadid) /* Setting up the Thread

what does this script display?

#include

#include

#include

#define ESC 27

#define NUM_THREADS 20

/*Compile with -pthread*/

void* doSomeThing(void *threadid)

/* Setting up the Thread */

{

long x = (long) threadid + 1;

printf("Hello World # %ld", x);

printf(" thread %ld ", (unsigned int)pthread_self());

/* So the thread will last */

sleep(15);

pthread_exit(NULL);

}

/*Main Driver */

int main()

{

printf("PID of this process: %d ", getpid());

/*Array holding all of the threads */

pthread_t threads[NUM_THREADS];

long i;

int err;

/* Setting up the Thread */

for(i=0; i

err = pthread_create(&threads[i], NULL, &doSomeThing, (void *)i);

if (err){

printf("ERROR; return code from pthread_create() is %d ", err);

exit(EXIT_FAILURE);

}

}

/* Keeping the program going */

sleep(25);

printf("Threads Terminating ");

pthread_exit(NULL);

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!