Question
Please give an original answer Considering the following code int y = 3; x = 1; void foo () { y = y + 1;
Please give an original answer
Considering the following code
int y = 3; x = 1;
void foo () {
y = y + 1;
x = y;
}
void bar () {
y = y * 2;
}
main () {
Thread t1 = createThread(foo);
Thread t2 = createThread(bar);
WaitForAllDone();
cout << x << y < } Note that function WaitForAllDone blocks the main thread until both threads it creates are done. Assume that memory load and memory store are atomic, but add and time are not atomic. Note, y = y + 1, consists of three assemby instructions : Load R1, y Add R1, 1, R1 Store R1, y x = y, consists of two assemby instructions : Load R1, y Store R1, x y = y * 2, consists of three assemby instructions : Load R1, y Mul R1, 2, R1 Store R1, y Registers not shared between the threads. Answer questions a and b a.) What is the maximum number of threads that are ever alive (this includes those one the ready or waiting lists, or running) in this program? b.) Give all possible outputs of this program. Explain your answer and be specific.
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