Suppose we have a program as follows: #include #include int i = 0; void *do_stuff(void *arg) { } i++; return NULL; int main() { } pthread_t tid1, tid2; pthread_create(&tid1, NULL, do_stuff, NULL); pthread_create(&tid2, NULL, do_stuff, NULL); pthread_join(tid1, NULL); pthread_join(tid2, NULL); printf("%d\n", i); return 0; Recall that because i is a global variable, i++; will compile to something like this: 400728: 8b 04 25 40 10 60 00 mov 0x601040,%eax 40072f: 83 c0 01 add $0x1,%eax 400732: 89 04 25 40 10 60 00 mov %eax,0x601040 A. (8 points) What are all possible outputs of this program? For each output, explain how the kernel could interleave execution of the two child threads to produce it.
Suppose we have a program as follows: #include #include int i = 0; void *do_stuff(void *arg) { } i++; return NULL; int main() { } pthread_t tid1, tid2; pthread_create(&tid1, NULL, do_stuff, NULL); pthread_create(&tid2, NULL, do_stuff, NULL); pthread_join(tid1, NULL); pthread_join(tid2, NULL); printf("%d\n", i); return 0; Recall that because i is a global variable, i++; will compile to something like this: 400728: 8b 04 25 40 10 60 00 mov 0x601040,%eax 40072f: 83 c0 01 add $0x1,%eax 400732: 89 04 25 40 10 60 00 mov %eax,0x601040 A. (8 points) What are all possible outputs of this program? For each output, explain how the kernel could interleave execution of the two child threads to produce it.
Related questions
Question
![Suppose we have a program as follows:
#include <stdio.h>
#include <pthread.h>
int i = 0;
void *do_stuff(void *arg) {
}
i++;
return NULL;
int main() {
}
pthread_t tid1, tid2;
pthread_create(&tid1, NULL, do_stuff, NULL);
pthread_create(&tid2, NULL, do_stuff, NULL);
pthread_join(tid1, NULL);
pthread_join(tid2, NULL);
printf("%d\n", i);
return 0;
Recall that because i is a global variable, i++; will compile to something like this:
400728: 8b 04 25 40 10 60 00 mov 0x601040,%eax
40072f: 83 c0 01 add $0x1,%eax
400732: 89 04 25 40 10 60 00 mov %eax,0x601040
A. (8 points) What are all possible outputs of this program? For each output, explain how the kernel
could interleave execution of the two child threads to produce it.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F3b25bdcc-1f5e-4716-88d3-d1e15ee2df25%2Ff0e7c82b-e1c9-41c6-b495-0c67f91c7d4c%2Fbu5od6od_processed.jpeg&w=3840&q=75)
Transcribed Image Text:Suppose we have a program as follows:
#include <stdio.h>
#include <pthread.h>
int i = 0;
void *do_stuff(void *arg) {
}
i++;
return NULL;
int main() {
}
pthread_t tid1, tid2;
pthread_create(&tid1, NULL, do_stuff, NULL);
pthread_create(&tid2, NULL, do_stuff, NULL);
pthread_join(tid1, NULL);
pthread_join(tid2, NULL);
printf("%d\n", i);
return 0;
Recall that because i is a global variable, i++; will compile to something like this:
400728: 8b 04 25 40 10 60 00 mov 0x601040,%eax
40072f: 83 c0 01 add $0x1,%eax
400732: 89 04 25 40 10 60 00 mov %eax,0x601040
A. (8 points) What are all possible outputs of this program? For each output, explain how the kernel
could interleave execution of the two child threads to produce it.
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)