Question: Q 3 . 1 : What is the smallest value y can contain after the code runs? Hint: One thread can complete the entire loop
Q: 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.
Q: 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 instead of the largest possible value for y would be Think about how to get this.
Q: Now, let's extend it further. If x was initialized to instead of still a shared variable what is the largest value y can contain after the code runs?
Hint: Answer Q correctly first to understand the execution pattern needed to get the worst case scenario.
If you answered Q 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.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
