Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Suppose we have a program as follows: #include #include int i = 0 ; void * do _ stuff ( void * arg ) {
Suppose we have a program as follows:
#include
#include
int i ;
void dostuffvoid arg
i;
return NULL;
int main
pthreadt tid tid;
pthreadcreate&tid NULL, dostuff, NULL;
pthreadcreate&tid NULL, dostuff, NULL;
pthreadjointid NULL;
pthreadjointid NULL;
printfd
i;
return ;
Recall that because iis a global variable, i; will compile to something like this:
: b mov xeax
f: c add $xeax
: mov eax,x
A 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
Initials:
Suppose we alter do stuff to look as follows:
void dostuffvoid arg attribute unused
int a;
for a ; a ; a
i;
return NULL;
Because the code is not optimized, there will be one loadincrementstore sequence per iteration of the
loop.
B points For each number, tell whether or not our program could output it and briefly explain why
or why not.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started