Skip to content

令和2年度 ITパスポート試験 問72

This question's explanation and your answers so far.

問72
頻出度★☆☆

2台の PC から一つのファイルを並行して更新した。ファイル中のデータ n に対する処理が①~④の順に行われたとき,データ n は最後にどの値になるか。ここで,データ n の初期値は10であった。 PC-A 【処理内容】 ① データ n を読み込み,5を引く。 ③ 処理①の結果を,データ n に書き込む。 PC-B 【処理内容】 ② データ n を読み込み,7を足す。 ④ 処理②の結果を,データ n に書き込む。

出典 令和2年度 ITパスポート試験 問72
解説

問 72

  • Incorrectア

    5 is the value right after ③ (PC-A's write). If ④ occurred before ③, or if PC-A wrote last, 5 would remain; but in this question's order ④ is last, so 5 is overwritten by ④'s value 17 and does not remain as the final value.

  • Incorrectイ

    10 is the initial value unchanged. This assumes that neither write takes effect, but in fact writes occur in both ③ and ④, and at least the result of the last write ④ becomes the final value, so it does not stay 10.

  • Incorrectウ

    12 is the value of 10−5+7, obtainable only under serial execution where locking (mutual exclusion) works correctly and one side finishes “read → compute → write” before the other reads the latest value. But in this question both PCs read the same initial value 10, so a lost update occurs and the result is not 12.

  • エ

    正解 The initial value of data n is 10, and the operations run in the order ①→②→③→④. In ①, PC-A reads n (=10), subtracts 5, and keeps the result 5 in its own memory. In ②, PC-B reads n (=10), adds 7, and keeps the result 17 in its own memory. At this point both PCs have read the same original value, 10. In ③, PC-A writes its result 5 to the file, making n=5; in ④, PC-B writes its result 17, making n=17. The last write is ④, so the final value is “17” (エ). The 5 written by PC-A is overwritten and lost by the write in ④ (loss of update = lost update).

ここがポイント
  • Without locking (mutual exclusion), when multiple operations update the same data in parallel, a later write overwrites an earlier one, causing a lost update, and the final value is the result of the last operation to write.
  • To maintain transaction isolation (the I = Isolation of the ACID properties), locking is required; without it, an inconsistent result arises as in this question.
用語

Your answers