Question: For the multi - threaded program below, what are all the valid outputs ( printed value of A ) for a sequentially consistent execution of

For the multi-threaded program below, what are all the valid outputs (printed value of A) for a sequentially consistent execution of the program? Before these threads start executing, A and B are both initialized to zero. Assume that each line of code below corresponds to one assembly instruction.
Thread 1
B=10;
A=30;
Thread 2
if (B-A>5)
then A =A+B;
print A:
What are possible valid outputs if the code in each thread is encapsulated within lock and unlock statements as shown below (again assuming a sequentially consistent processor)?
Thread 1
lock(L1);
B=10;
A =30;
unlock(L1);
Thread 2
lock(L1);
if (B-A >5) then
A =A+ B;
print A;
unlock(L1);

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!