Question: #include #include #include #define NTHREADS 10 pthread_t threads[NTHREADS]; void go (int n) { printf(Hello from thread %d , n); thread_exit(100 + n); // REACHED? }

#include #include #include #define NTHREADS 10 pthread_t threads[NTHREADS]; void go (int n) { printf("Hello from thread %d ", n); thread_exit(100 + n); // REACHED? } int main() { int i; for (i = 0; i < NTHREADS; i++) thread_create(&threads[i], &go, i); for (i = 0; i < NTHREADS; i++) { int exitValue = thread_join(threads[i]); printf("Thread %d returned with %ld ", i, exitValue); } printf("Main thread done. "); }

7.For the threadHello program in Figure 4.6, the procedure go() has the parameter np and the local variable n. Are these variables per-thread or shared state? Where does the compiler store these variables states?

8. For the threadHello program in Figure 4.6, the procedure main() has local variables such as i and exitValue. Are these variables per-thread or shared state? Where does the compiler store these variables?

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!