Atomic updates: Difference between revisions

m
added whitespace before the TOC, added a Task (bold) header, added other whitespace to the task's preamble.
(/* {{header|Go}} big simplification. drop variant solutions, just show one solution that works well.)
m (added whitespace before the TOC, added a Task (bold) header, added other whitespace to the task's preamble.)
Line 1:
{{task|Concurrency}}{{requires|Concurrency}}
{{requires|Concurrency}}
 
;Task:
Define a data type consisting of a fixed number of 'buckets', each containing a nonnegative integer value, which supports operations to:
# get the current value of any bucket
# remove a specified amount from one specified bucket and add it to another, preserving the total of all bucket values, and [[wp:Clamping (graphics)|clamping]] the transferred amount to ensure the values remain nonnegativenon-negative
 
----
Line 12 ⟶ 14:
# At whatever rate is convenient, display (by any means) the total value and, optionally, the individual values of each bucket.
 
<br>
The display task need not be explicit; use of e.g. a debugger or trace tool is acceptable provided it is simple to set up to provide the display.
 
----
 
This task is intended as an exercise in ''atomic'' operations. &nbsp; The sum of the bucket values must be preserved even if the two tasks attempt to perform transfers simultaneously, and a straightforward solution is to ensure that at any time, only one transfer is actually occurring — that the transfer operation is ''atomic''.
<br><br>
 
=={{header|Ada}}==