Anonymous user
Atomic updates: Difference between revisions
Refactored process creation code into a new function
(Added Mathematica) |
(Refactored process creation code into a new function) |
||
Line 2,702:
(de pickBucket ()
(db 'key '+Bucket (rand 1 *Buckets)) )
# Create process
(de process (QuadFunction)
(unless (fork)▼
(seed *Pid) # Ensure local random sequence▼
(loop
(let (B1 (pickBucket) B2 (pickBucket)) # Pick two buckets 'B1' and 'B2'▼
# First process
(process
▲(unless (fork)
(quote (B1 V1 B2 V2)
▲ (seed *Pid) # Ensure local random sequence
(
▲ (let (B1 (pickBucket) B2 (pickBucket)) # Pick two buckets 'B1' and 'B2'
((> V2
(inc> B2 'val) )▼
▲ ((> V2 V1)
▲ (inc> B1 'val) ) ) )
▲ (commit 'upd) ) ) ) # Close transaction
# Second process
(process
(quote (B1 V1 B2 V2)
(
(
▲ (dbSync) # Atomic DB operation
((> V2 V1 0)
▲ (let (V1 (; B1 val) V2 (; B2 val)) # Get current values
(inc> B2
(dec> B1 'val) ) ) )
▲ ((> V2 V1 0)
▲ (commit 'upd) ) ) ) ) # Close transaction
# Third process
|