같은 갱신도 읽기와 쓰기가 엇갈리면 결과가 달라질 수 있다.
각 읽기와 쓰기를 별도 단계로 드러내면 유한한 실행 순서 하나에서 갱신 손실을 직접 볼 수 있습니다.
두 갱신이 어느 쪽도 끝나기 전에 같은 잔액을 읽으면 무엇이 사라질까요?
- Separate each transaction read from its later write
- Recognize a write computed from a stale shared value
- Enumerate the exact step order of a finite schedule
- Compare a lost-update result with a serialized result
The deposit adds 10 and the withdrawal subtracts 20. In the first schedule, both operations read 100. The deposit writes 110, but the withdrawal still computes from its earlier read and writes 80. The later write replaces the deposit result, so the final balance does not contain both changes.
The second schedule lets the deposit read and write before the withdrawal reads. The withdrawal therefore sees 110 and writes 90. These programs enumerate two already chosen finite schedules. They do not create threads or a serializer, and they do not establish the result of every possible interleaving.
(begin
(define balance 100)
(define deposit-read balance)
(define withdraw-read balance)
(define deposit-write (+ deposit-read 10))
(set! balance deposit-write)
(define withdraw-write (- withdraw-read 20))
(set! balance withdraw-write)
(list (list 'deposit 'read deposit-read)
(list 'withdraw 'read withdraw-read)
(list 'deposit 'write deposit-write)
(list 'withdraw 'write withdraw-write)
(list 'final balance)))- 출력
- —
- 값
- —
- 진단
- —
The first program returns ((deposit read 100) (withdraw read 100) (deposit write 110) (withdraw write 80) (final 80)). The serialized program returns ((deposit read 100) (deposit write 110) (withdraw read 110) (withdraw write 90) (final 90)).
Follow the two initial balance reads before either assignment in the first run, then locate the writes of 110 and 80. In the second run, the withdrawal read follows the write of 110. The bounded traces describe only these two explicit schedules.
힌트를 보기 전에 프로그램을 바꿔 보세요.
In the first schedule, place the withdrawal write before the deposit write. Predict the final balance and name the update that is then lost.
힌트 하나 보기
Both writes were computed from 100, so the write that occurs last determines the final balance.