Question: #include #include #include #include void *go(void *); #define NTHREADS 20 pthread_t threads[NTHREADS]; int main() { int i; for (i = 0; i < NTHREADS; i++)

#include #include #include #include void *go(void *); #define NTHREADS 20 pthread_t threads[NTHREADS]; int main() { int i; for (i = 0; i < NTHREADS; i++) pthread_create(&threads[i], NULL, go, (void *)(size_t)i); printf("Main thread done. "); return 0; } void *go(void *arg) { printf("Hello from thread %d with iteration %d ", (int)(unsigned long)pthread_self(), (int)(unsigned long)(size_t *)arg); sleep(15); pthread_exit(0); }

The function go() in the program in Step 1 has the parameter arg passed a local variable. Is the variable per thread variable or a shared state? Where does the compiler store the variables state?

The main() in the program in Step 1 has local variable i. Is this variable per thread variable or a shared state? Where does the compiler store this variable?

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!