IPA IP 2020 Question 72
A question IPA Japan published in 令和2年度 10月 ITパスポート試験 公開問題 問72, translated into English. ITPEC is based on the same exams.
A single file was updated concurrently from two (2) PCs. When the processing for data n in the file was performed in the order of ① through ④, which of the following is the final value of data n? Here, the initial value of data n was 10.
Explanation
17 — PC-B reads data n before PC-A writes it back, so PC-B's write overwrites PC-A's update: a lost update.
Each PC reads the value into its own memory, calculates there, and writes the result back later. Following the order ① to ④:
- •① PC-A reads n = 10 and calculates 10 − 5 = 5; the file still holds 10
- •② PC-B reads n = 10, the value still in the file, and calculates 10 + 7 = 17
- •③ PC-A writes 5: n = 5
- •④ PC-B writes 17: n = 17
PC-A's subtraction is lost. Run one after the other, the two updates would give 10 − 5 + 7 = 12. Exclusive control (locking) prevents this: PC-A locks data n from ① until ③, so PC-B's read has to wait for the updated value.
Answer (d)
Why not others:
- •(a) 5 — the value after ③; it ignores PC-B's later write ④
- •(b) 10 — the initial value, as if neither write had happened
- •(c) 12 — the correct result if the updates ran one after the other under exclusive control, but here ② reads before ③ writes
Key rule: When two processes both read the same data before either writes it, the last write wins and the other update is lost; locking from the read to the write prevents it.
Databases · AI-written, may contain errors
This question comes from the past questions IPA Japan publishes, translated into English by ITPEC Practice. ITPEC Practice is an independent study tool and is not affiliated with IPA or ITPEC. See the original paper (PDF) or Report an issue.