Shared integer variable TOTAL is initially 4. Suppose task A adds 2 to TOTAL, ta
ID: 3627706 • Letter: S
Question
Shared integer variable TOTAL is initially 4. Suppose task A adds 2 to TOTAL, task B multiplies TOTAL by 3. Each of the two tasks performs its operation on TOTAL with the following three-step process:
1. Fetch the value of TOTAL.
2. Perform the arithmetic operation.
3. Put the new value back in TOTAL.
Without competition synchronization, what could be the possible values for TOTAL after both task A and B finish their executions? Justify your answer. Explain why competition synchronization can address the above problem.
Explanation / Answer
Without competition synchronization, three different values could be result from these operations.
If task A completes its operations before task B begins, the value will be 18.
But if both A and B fetches the value of total before either task put its new value back the result will be incorrect.
If A puts the value of the Total result will be 18.
If B puts the value of the Total result will be 14.
This type of situation is called Race Condition, because two are more tasks are racing to use shared resource and the behaviour of the program depends on which tasks arrives first.
Here competition synchronization can address the above problem.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.