以下の内容はhttps://kiririmode.hatenablog.jp/entry/20080713/p5より取得しました。


問題3-44 (3.4.1 The Nature of Time in Concurrent Systems)

2 つの口座の残高を交換する exchange は,直列化しとかないとヒドいことになる.

(define (exchange account1 account2)
  (let ((difference (- (account1 'balance)
                       (account2 'balance))))
    ((account1 'withdraw) difference)
    ((account2 'deposit) difference)))

では,一定金額 amount をある口座から他方の口座へ移動させる transfer を直列化する必要はあるのかという話.

(define (transfer from-account to-account amount)
  ((from-account 'withdraw) amount)
  ((to-account 'deposit) amount))

exchange を直列化する必要があったのは,計算した 2 口座 (account1 と account2) 間の残高の差が,withdraw と deposit を完了するまで一定に保たれていなければならないから.この間にどちらかの口座の残高が変更された場合,この処理は破綻する.

ところが transfer は,あらかじめ処理する金額が決まっている.withdraw と deposit の間であれ,前後であれ,口座の残高が変わったとしても一貫性は保たれる.そのため,直列化する必要はない.んじゃないかな.




以上の内容はhttps://kiririmode.hatenablog.jp/entry/20080713/p5より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14