Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
|
|
@ -21,39 +21,40 @@
|
|||
(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'
|
||||
(unless (== B1 B2) # Found two different ones?
|
||||
(dbSync) # Atomic DB operation
|
||||
(let (V1 (; B1 val) V2 (; B2 val)) # Get current values
|
||||
(QuadFunction B1 V1 B2 V2) )
|
||||
(commit 'upd) ) ) ) ) ) # Close transaction
|
||||
|
||||
|
||||
# First process
|
||||
(unless (fork)
|
||||
(seed *Pid) # Ensure local random sequence
|
||||
(loop
|
||||
(let (B1 (pickBucket) B2 (pickBucket)) # Pick two buckets 'B1' and 'B2'
|
||||
(dbSync) # Atomic DB operation
|
||||
(let (V1 (; B1 val) V2 (; B2 val)) # Get current values
|
||||
(cond
|
||||
((> V1 V2)
|
||||
(dec> B1 'val) # Make them closer to equal
|
||||
(inc> B2 'val) )
|
||||
((> V2 V1)
|
||||
(dec> B2 'val)
|
||||
(inc> B1 'val) ) ) )
|
||||
(commit 'upd) ) ) ) # Close transaction
|
||||
(process
|
||||
(quote (B1 V1 B2 V2)
|
||||
(cond
|
||||
((> V1 V2)
|
||||
(dec> B1 'val) # Make them closer to equal
|
||||
(inc> B2 'val) )
|
||||
((> V2 V1)
|
||||
(dec> B2 'val)
|
||||
(inc> B1 'val) ) ) ) )
|
||||
|
||||
# Second process
|
||||
(unless (fork)
|
||||
(seed *Pid) # Ensure local random sequence
|
||||
(loop
|
||||
(let (B1 (pickBucket) B2 (pickBucket)) # Pick two buckets 'B1' and 'B2'
|
||||
(unless (== B1 B2) # Found two different ones?
|
||||
(dbSync) # Atomic DB operation
|
||||
(let (V1 (; B1 val) V2 (; B2 val)) # Get current values
|
||||
(cond
|
||||
((> V1 V2 0)
|
||||
(inc> B1 'val) # Redistribute them
|
||||
(dec> B2 'val) )
|
||||
((> V2 V1 0)
|
||||
(inc> B2 'val)
|
||||
(dec> B1 'val) ) ) )
|
||||
(commit 'upd) ) ) ) ) # Close transaction
|
||||
(process
|
||||
(quote (B1 V1 B2 V2)
|
||||
(cond
|
||||
((> V1 V2 0)
|
||||
(inc> B1 'val) # Redistribute them
|
||||
(dec> B2 'val) )
|
||||
((> V2 V1 0)
|
||||
(inc> B2 'val)
|
||||
(dec> B1 'val) ) ) ) )
|
||||
|
||||
# Third process
|
||||
(unless (fork)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue