Question: Q 3 . 1 : What is the smallest value y can contain after the code runs? Hint: One thread can complete the entire loop

Q3.1: What is the smallest value y can contain after the code runs?
Hint: One thread can complete the entire loop while the other thread has just started.
100%
Q3.2: What is the largest value y can contain after the code runs?
Hint: Since x is relatively small (loop count is small), try writing out the different y values for each thread as they execute. If you want to maximize the value of y, how can two threads 'force' more iterations to happen?
If x was initialized to 2 instead of 3, the largest possible value for y would be 5. Think about how to get this.
0%
Q3.3: Now, let's extend it further. If x was initialized to 10 instead of 3(still a shared variable), what is the largest value y can contain after the code runs?
Hint: Answer Q3.2 correctly first to understand the execution pattern needed to get the worst case scenario.
If you answered Q3.2 by brute force (by writing all cases as each thread executes), you can find a formula on the worst case value of y given the initial value of x to help you answer this question.
0%

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!