8.16.0.1
5.1 Atomic Booleans
(require rebellion/concurrency/atomic/boolean) | |
package: rebellion |
An atomic boolean is a thread-safe, future-safe, kill-safe, break-safe, and wait-free mutable object containing a single boolean.
procedure
(atomic-boolean? v) → boolean?
v : any/c
A predicate for atomic booleans.
procedure
(make-atomic-boolean initial-value) → atomic-boolean?
initial-value : boolean?
Constructs a new atomic boolean and sets it to initial-value.
procedure
(atomic-boolean-get bool) → boolean?
bool : atomic-boolean?
Returns the current value of bool.
Examples:
> (define bool (make-atomic-boolean #false)) > (atomic-boolean-get bool) #f
procedure
(atomic-boolean-set! bool replacement) → void?
bool : atomic-boolean? replacement : boolean?
Sets the current value of bool to replacement.
Examples:
> (define bool (make-atomic-boolean #false)) > (atomic-boolean-set! bool #true) > (atomic-boolean-get bool) #t
procedure
(atomic-boolean-compare-and-set! bool expected replacement) → boolean? bool : atomic-boolean? expected : boolean? replacement : boolean?
Attempts to set bool to replacement, succeeding if and only
if its current value is expected. Returns a boolean indicating whether
or not the operation succeeded.
Examples:
> (define bool (make-atomic-boolean #true)) > (atomic-boolean-compare-and-set! bool #false #true) #f
> (atomic-boolean-get bool) #t
> (atomic-boolean-compare-and-set! bool #true #false) #t
> (atomic-boolean-get bool) #f
procedure
(atomic-boolean-compare-and-exchange! bool expected replacement) → boolean? bool : atomic-boolean? expected : boolean? replacement : boolean?
Attempts to set bool to replacement, succeeding if and only
if its current value is expected. Returns the value of bool
before the exchange. If the returned value is equal to expected, that
indicates the exchange succeeded.
Examples:
> (define bool (make-atomic-boolean #false)) > (atomic-boolean-compare-and-exchange! bool #true #false) #f
> (atomic-boolean-get bool) #f
> (atomic-boolean-compare-and-exchange! bool #false #true) #f
> (atomic-boolean-get bool) #t
procedure
(atomic-boolean-get-then-set! bool replacement) → boolean? bool : atomic-boolean? replacement : boolean?
Sets bool to replacement and returns its previous value.
Examples:
> (define bool (make-atomic-boolean #false)) > (atomic-boolean-get-then-set! bool #true) #f
> (atomic-boolean-get bool) #t