Talk:Atomic updates: Difference between revisions

clarified, I hope. yes, transfer is nonatomic.
(Transfer is clarified)
(clarified, I hope. yes, transfer is nonatomic.)
Line 14:
:::::Assume that this entire routine is executed atomically. It preserves both invariants -- the sum of buckets (by changing two buckets by equal and opposite amounts) and that each bucket is positive (by clamping the amount transferred). Why can't you do the same thing in Ada? --[[User:Kevin Reid|Kevin Reid]] 18:48, 18 May 2009 (UTC)
::::::Ah, finally I've got it. Thanks for an explanation. That is no problem. Can you move this definition of transfer into the task description? E.g. "takes two indices and then adds a specified amount to the bucket indexed by one and subtracts it from one indexed by another index, but no more than its total value." One question remains, how can this transfer be used to make pairs of buckets equal (averaging)? You need an atomic read + decide + update operation. Or this is not required by the task? --[[User:Dmitry-kazakov|Dmitry-kazakov]] 19:24, 18 May 2009 (UTC)
:::::::I've tried to clarify the description. And yes, checking the current value is explicitly non-atomic. The idea is that in the absence of disturbance, the neatening task ''would'' achieve its goal; each step is, on average, an improvement, unless there is another task specifically perversely adjusting the buckets just in time. This isn't intended to be a sensible example of how to accomplish anything on a small data set; it's intended to be solely an exercise in preserving invariants despite sloppy/buggy/competing clients. --[[User:Kevin Reid|Kevin Reid]] 19:39, 18 May 2009 (UTC)