Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Shared integer variable TOTAL is initially 3. Suppose task A adds 1 to TOTAL , t

ID: 3578817 • Letter: S

Question

Shared integer variable TOTAL is initially 3.

Suppose task A adds 1 to TOTAL, task B multiplies TOTAL by 2. Each of the two tasks performs its operation on TOTAL with the following three-step process:

Fetch the value of TOTAL.

Perform the arithmetic operation.

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

4-scenarios

A-start, A-finish, B-start, B-finish => Total = 8

B-start, B-finsh, A-start, A-finsih => Total = 7

A-start, B-start, A-finish, B-finsh => Total = 6 (because B read it as 3 and last persisted by it)

A-start, B-start, B-finish, A-finsih => Total = 4 (A read it as 3 and last persisted by it)

Competitive synchornization will solve this problem by eradicating overlapping processing by A&B.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote