Skip to content

平成21年度 春期 ITパスポート試験 問82

This question's explanation and your answers so far.

問82
頻出度★☆☆

データ D を更新する二つの処理 A,B が,①→③→②→④ のタイミングで実行された場合,D の値は幾らになるか。ここで,D の初期値は 2 とする。

処理A 〔処理内容〕処理B 〔処理内容〕
① D を読み込み,3倍する。③ D を読み込み,5を加える。
② ①の結果を,D に書き込む。④ ③の結果を,D に書き込む。
出典 平成21年度 春期 ITパスポート試験 問82
解説

問 82

  • Incorrectア

    6 is the value right after ② writes the result of ① (2×3), but Process B then overwrites it with 7 in ④, so it does not remain as the final value. 6 would be the answer in the order ①→③→④→②, that is, when Process B writes first and Process A writes afterwards, which differs from the ①→③→②→④ order of this question.

  • イ

    正解 The correct answer is イ (7). Separate reading (getting the current value) from writing (updating it), and trace both the value of D and the result each process is holding, following the order ①→③→②→④. The initial value is D=2. ① Process A reads D and computes 2×3=6, but at this point it has not written anything yet, so D is still 2. ③ Process B reads D. Because the write in ② has not been done yet, Process B reads the old value 2 and computes 2+5=7. ② Process A writes the result of ①, which is 6, into D, so D becomes 6. ④ Process B writes the result of ③, which is 7, into D, overwriting D=6, so D becomes 7. The value written last, by Process B, is the one that remains, so the answer is 7. Here the update made by Process A (6) has been overwritten by Process B and disappeared; this is the lost update that happens when no exclusive control (locking) is applied.

  • Incorrectウ

    11 is the value when Process B reads only after Process A has completely finished, that is, the value when the steps run serially in the order ①→②→③→④ ((2×3)+5=11). In this question ③ runs before ②, so Process B reads the initial value 2 rather than the updated 6, and the result does not become 11. Do not confuse it with the ideal result obtained when exclusive control works correctly.

  • Incorrectエ

    21 is the value when Process A reads only after Process B has finished first, that is, the value when the steps run serially in the order ③→④→①→② ((2+5)×3=21). In this question ① comes first, so Process A reads 2, and a situation where 7 is multiplied by 3 never arises.

ここがポイント
  • If several processes update the same data at the same time without exclusive control (locking), both of them read the old value from before the update, and the side that writes later overwrites the earlier update. This is called a lost update, and to prevent it the data must be locked from the moment one side reads it until it finishes writing, making the other side wait.
  • This type of question can be solved reliably by strictly distinguishing reading (obtaining the value the data has at that moment) from writing (reflecting into the data the result the process has computed and is holding), and then following the specified timing order step by step in a table of the value of the data and the value each process holds.
用語

Your answers