box-extra: box utilities
(require box-extra) | package: box-extra-lib |
Extra utilities for working with boxes.
1 Reference
value
box-update-strategy/c : (or/c 'busy 'semaphore)
value
procedure
(make-box-update-proc b [strategy]) → box-update-proc/c
b : box? strategy : box-update-strategy/c = 'semaphore
The 'semaphore strategy synchronizes retrying threads using a semaphore. See box-update/semaphore! for details.
The 'busy strategy retries without any sort of backoff. See box-update/busy! for details.
> (require box-extra) > (define b (box 0)) > (define update-b! (make-box-update-proc b)) > (update-b! add1) 1
> (unbox b) 1
Prefer box-update/semaphore! over this function. Only use this function if you’re sure that multiple threads won’t attempt to update b concurrently.
procedure
(box-update/semaphore! b sema proc) → any/c
b : box? sema : semaphore? proc : (-> any/c any/c)
The sema argument must have an initial count of 1.
> (require box-extra) > (define b (box 0)) > (define sema (make-semaphore 1))
> (define thds (list (thread (λ () (box-update/semaphore! b sema add1))) (thread (λ () (box-update/semaphore! b sema add1))))) > (for-each thread-wait thds) > (unbox b) 2
1.1 Unsafe API
(require box-extra/unsafe) | package: box-extra-lib |
procedure
(make-unsafe-box-update-proc b [strategy]) → box-update-proc/c
b : box? strategy : box-update-strategy/c = 'semaphore
procedure
(unsafe-box-update/busy! b proc) → any/c
b : box? proc : (-> any/c any/c)
procedure
(unsafe-box-update/semaphore! b sema proc) → any/c
b : box? sema : semaphore? proc : (-> any/c any/c)