Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Google Analytics 4 The Data Driven Marketing Revolution

Authors: Galen Poll

2024th Edition

B0CRK92F5F, 979-8873956234

More Books

Students also viewed these Databases questions

Question

Describe the new structures for the HRM function. page 676

Answered: 1 week ago