#include<stdio.h> #include<stdlib.h> #include<pthread.h> #define NTHREADS 10 pth
ID: 3864562 • Letter: #
Question
#include<stdio.h>
#include<stdlib.h>
#include<pthread.h>
#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. ");
}
Suppose that we delete the second for loop so that the main routine simply creates NTHREADS threads and then prints “Main thread done.” What are the possible outputs of the program now?
Explanation / Answer
Hello.. First of all there are errors in this method
Below is the code i ll paste and list out errors ..
void go (int n) {
printf("Hello from thread %d ", n);
thread_exit(100 + n); // Error - Line 1
// REACHED?
}
Hello from thread + n and also Main thread done in new line.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.