mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-16 17:27:33 +02:00
Document new concurrency objects
This commit is contained in:
parent
48376779e3
commit
c51fb226ce
1 changed files with 73 additions and 0 deletions
|
@ -15,6 +15,7 @@ This library complements the multithreading support provided by [SRFI 18](../srf
|
||||||
|
|
||||||
[General](#general)
|
[General](#general)
|
||||||
- [`deref`](#deref)
|
- [`deref`](#deref)
|
||||||
|
- [`realized?`](#realized)
|
||||||
|
|
||||||
[Atoms](#atoms)
|
[Atoms](#atoms)
|
||||||
- [`make-atom`](#make-atom)
|
- [`make-atom`](#make-atom)
|
||||||
|
@ -23,6 +24,16 @@ This library complements the multithreading support provided by [SRFI 18](../srf
|
||||||
- [`swap!`](#swap)
|
- [`swap!`](#swap)
|
||||||
- [`compare-and-set!`](#compare-and-set)
|
- [`compare-and-set!`](#compare-and-set)
|
||||||
|
|
||||||
|
[Delays](#delays)
|
||||||
|
- [`shared-delay?`](#shared-delay)
|
||||||
|
- [`shared-delay`](#shared-delay-1)
|
||||||
|
- [`make-shared-delay`](#make-shared-delay)
|
||||||
|
|
||||||
|
[Promises](#promises)
|
||||||
|
- [`shared-promise?`](#shared-promise)
|
||||||
|
- [`make-shared-promise`](#make-shared-promise)
|
||||||
|
- [`deliver`](#deliver)
|
||||||
|
|
||||||
[Futures](#futures)
|
[Futures](#futures)
|
||||||
- [`future?`](#future)
|
- [`future?`](#future)
|
||||||
- [`future`](#future-1)
|
- [`future`](#future-1)
|
||||||
|
@ -116,6 +127,12 @@ Predicate that returns `#t` if `obj` is immutable and `#f` otherwise.
|
||||||
|
|
||||||
Dereference; returns the current value of the given concurrency object.
|
Dereference; returns the current value of the given concurrency object.
|
||||||
|
|
||||||
|
### realized?
|
||||||
|
|
||||||
|
(realized? obj)
|
||||||
|
|
||||||
|
Returns `#t` if a value has been produced for a promise, delay, or future. Otherwise returns `#f`.
|
||||||
|
|
||||||
## Atoms
|
## Atoms
|
||||||
|
|
||||||
This section provides atomic operations modelled after Clojure's [Atoms](https://clojure.org/reference/atoms).
|
This section provides atomic operations modelled after Clojure's [Atoms](https://clojure.org/reference/atoms).
|
||||||
|
@ -181,6 +198,62 @@ Atomically changes the value of `atom` to `newval` but only if the value of `ato
|
||||||
|
|
||||||
Based on the procedure of the same name from Clojure.
|
Based on the procedure of the same name from Clojure.
|
||||||
|
|
||||||
|
## Delays
|
||||||
|
|
||||||
|
A delay is created to execute code at a later time. When the result is required any thread can call `deref` to generate it. Once executed the result is cached so it is available for other threads.
|
||||||
|
|
||||||
|
Delays are based on delay objects from Clojure.
|
||||||
|
|
||||||
|
Note delays are referred to as `shared-delay` in the code to differentiate them from the single-threaded `delay` provided by `(scheme lazy)`.
|
||||||
|
|
||||||
|
### shared-delay?
|
||||||
|
|
||||||
|
(shared-delay? obj)
|
||||||
|
|
||||||
|
Type predicate, returns `#t` if `obj` is a shared delay and `#f` otherwise.
|
||||||
|
|
||||||
|
### shared-delay
|
||||||
|
|
||||||
|
*Syntax*
|
||||||
|
|
||||||
|
(shared-delay body ...)
|
||||||
|
|
||||||
|
Create a delay object that will execute `body` when dereferenced.
|
||||||
|
|
||||||
|
### make-shared-delay
|
||||||
|
|
||||||
|
(make-shared-delay thunk)
|
||||||
|
|
||||||
|
Create a delay object that will execute `thunk` when dereferenced.
|
||||||
|
|
||||||
|
## Promises
|
||||||
|
|
||||||
|
A promise allows one or more threads to wait for a value to be generated by another thread. When `deref` is called on a promise the calling thread will block until a value is delivered to the promise, via another thread calling `deliver`.
|
||||||
|
|
||||||
|
Promises are based off of promise objects from Clojure.
|
||||||
|
|
||||||
|
Note promises are referred to as `shared-promise` in the code to differentiate them from the single-threaded promise functionality provided by `(scheme lazy)`.
|
||||||
|
|
||||||
|
### shared-promise?
|
||||||
|
|
||||||
|
(shared-promise? obj)
|
||||||
|
|
||||||
|
Type predicate, returns `#t` if `obj` is a shared promise and `#f` otherwise.
|
||||||
|
|
||||||
|
### make-shared-promise
|
||||||
|
|
||||||
|
(make-shared-promise)
|
||||||
|
|
||||||
|
Create a new promise object.
|
||||||
|
|
||||||
|
### deliver
|
||||||
|
|
||||||
|
(deliver promise obj)
|
||||||
|
|
||||||
|
Assign `promise` the value `obj` and unblock any threads that were waiting for the promise.
|
||||||
|
|
||||||
|
Note that subsequent calls to `deliver` have no effect. A value may only be delivered once to a given promise.
|
||||||
|
|
||||||
## Futures
|
## Futures
|
||||||
|
|
||||||
Futures are used to perform computations on another thread. The results are cached and may be retrieved later using `deref`. Note that `deref` will block on a future until a result is generated by the other thread.
|
Futures are used to perform computations on another thread. The results are cached and may be retrieved later using `deref`. Note that `deref` will block on a future until a result is generated by the other thread.
|
||||||
|
|
Loading…
Add table
Reference in a new issue