The clj-con Reference Manual

This is the clj-con Reference Manual, version 1.0.0, generated automatically by Declt version 4.0 beta 2 "William Riker" on Sun Dec 15 05:40:44 2024 GMT+0.

Table of Contents


1 Introduction


2 Systems

The main system appears first, followed by any subsystem dependency.


2.1 clj-con

Clojure-style concurrency operations like ‘future‘, ‘promise‘, and ‘atom‘.

Author

Dave Tenny

Source Control

(GIT https://github.com/dtenny/clj-con)

Bug Tracker

https://github.com/dtenny/clj-con/issues

License

MIT

Version

1.0.0

Dependencies
  • bordeaux-threads (system).
  • atomics (system).
Source

clj-con.asd.

Child Components

3 Files

Files are sorted by type and then listed depth-first from the systems components trees.


3.1 Lisp


3.1.1 clj-con/clj-con.asd

Source

clj-con.asd.

Parent Component

clj-con (system).

ASDF Systems

clj-con.

Packages

clj-con-asd.


3.1.2 clj-con/package.lisp

Source

clj-con.asd.

Parent Component

clj-con (system).

Packages

clj-con.


3.1.3 clj-con/clj-con.lisp

Dependency

package.lisp (file).

Source

clj-con.asd.

Parent Component

clj-con (system).

Public Interface
Internals

3.1.4 clj-con/atom.lisp

Dependency

clj-con.lisp (file).

Source

clj-con.asd.

Parent Component

clj-con (system).

Public Interface
Internals

4 Packages

Packages are listed by definition order.


4.1 clj-con-asd

Source

clj-con.asd.

Use List
  • asdf/interface.
  • common-lisp.

4.2 clj-con

Functions and macros that implement concurrency operations styled after Clojure operators such as ‘future‘ and ‘promise‘. Note that timeouts in this module are also similar to those found in Clojure and/or the JVM and are expressed as millisecond values, even though Common Lisp normally specifies timeouts as seconds (or fractions thereof).

Source

package.lisp.

Use List

common-lisp.

Public Interface
Internals

5 Definitions

Definitions are sorted by export status, category, package, and then by lexicographic order.


5.1 Public Interface


5.1.1 Macros

Macro: future (&body body)

Takes a body of expressions and yields a future object that will
invoke the body in another thread, and will cache the result and
return it on all subsequent calls to deref. If the computation has
not yet finished, calls to deref will block, unless the variant of
deref with timeout is used. See also - realized?.

Note that multiple-value returns are lost, only the first (assumed) value is returned.

Package

clj-con.

Source

clj-con.lisp.


5.1.2 Ordinary functions

Function: atom (&optional x)

Creates and returns an Atom with an initial value of x.
Does not support validator and metadata arguments of the Clojure equivalent.

Package

clj-con.

Source

atom.lisp.

Function: atom? (object)
Package

clj-con.

Source

atom.lisp.

Function: compare-and-set! (atom oldval newval)

Atomically sets the value of atom to newval if and only if the current value of the atom is identical (EQ) to oldval. Returns non-NIL if the set happened, NIL if it did not.

Package

clj-con.

Source

atom.lisp.

Function: deliver (promise val)

Delivers the supplied value to the promise, allowing the return of any blocked derefs. A subsequent call to deliver on a promise will have no effect.

The first deliver call will return the promise.
Subsequent calls to deliver return NIL.
This is compatible with Clojure, though note that
‘(deliver p 123) (deliver p true)‘ in clojure causes a ClassCastException,
whereas here the second call returns false.

Package

clj-con.

Source

clj-con.lisp.

Function: future-call (thunk)

Takes a function of no args and yields a future object that will invoke the function in another thread, and will cache the result and return it on all subsequent calls to deref. If the computation has not yet finished, calls to deref will block, unless the variant of deref with timeout is used. See also - realized?.

Package

clj-con.

Source

clj-con.lisp.

Function: future-cancel (future)

Cancels the future, if possible.
Returns T if the cancellation request is successful, NIL if it is not.
Note that interrupting threads in CL is not as tidy as clojure See SB-THREAD::INTERRUPT-THREAD. Unless threads are carefully using sb-sys:without-interrupts,
their unwind handlers may not work right. Don’t expect something as robust as the JVM’s InterruptedException.

Package

clj-con.

Source

clj-con.lisp.

Function: future-cancelled? (future)

Return T if the future was explicitly (and successfully) cancelled, NIL otherwise.

Package

clj-con.

Source

clj-con.lisp.

Function: future-done? (future)

Return T if future is done, NIL otherwise.
It is ’done’ if it is in any state other than :ready (thus hasn’t started, or is executing the supplied forms).

Package

clj-con.

Source

clj-con.lisp.

Function: future? (object)
Package

clj-con.

Source

clj-con.lisp.

Function: promise ()

Returns a promise object that can be read with ‘deref‘ and set, once only, with ‘deliver‘. Calls to deref prior to delivery will block unless the variant of deref with timeout is used. All subsequent derefs will return the same delivered value without blocking. See also - ‘realized?‘.

Package

clj-con.

Source

clj-con.lisp.

Function: reset! (atom newval)

Sets the value of atom to newval without regard for the current value. Returns newval.

Package

clj-con.

Source

atom.lisp.

Function: reset-vals! (atom newval)

Sets the value of atom to newval.
Returns the value of the atom before and after the reset as multiple values. (Note difference from Clojure which does not have multiple value returns).

Package

clj-con.

Source

atom.lisp.

Function: swap! (atom f &rest args)

Atomically swaps the value of atom to be:
(apply f current-value-of-atom args). Note that f may be called multiple times, and thus should be free of side effects. Returns the value that was swapped in.

Package

clj-con.

Source

atom.lisp.

Function: swap-vals! (atom f &rest args)

Atomically swaps the value of atom to be:
(apply f current-value-of-atom args). Note that f may be called
multiple times, and thus should be free of side effects. Returns un-Clojure-y multiple values ‘(old new)‘, the value of the atom before and after the swap.

Package

clj-con.

Source

atom.lisp.


5.1.3 Generic functions

Generic Function: deref (thing &optional timeout-ms timeout-val)

Used on various objects to obtain a value from an asynchronous construct.

When applied to an atom, yields the current value of the atom.

When applied to a future, will block if computation not complete.
If the future completed unsuccessfully, deref will signal either cancellation-exception
or execution-exception depending on whether it was cancelled or unwound due to unhandled conditions.

When applied to a promise, will block until a value is delivered.

When called with timeout options (valid only for promises and futures),
can be used for blocking and will return
timeout-val if the timeout (in milliseconds) is reached before a
value is available. See also - realized?.

Note that a call to ‘deref‘ with a timeout the returns the timeout value
does not force the promise/future to be ‘realized?‘, it may remain unrealized.

Note that if timeout-ms is supplied, timeout-val is also required, to maintain
parity with Clojure’s arity-1 and arity-3 (but no arity-2) calls.

Package

clj-con.

Source

clj-con.lisp.

Methods
Method: deref ((atom atom) &optional timeout-ms timeout-val)
Source

atom.lisp.

Method: deref ((f future) &optional timeout-ms timeout-val)
Method: deref ((p promise) &optional timeout-ms timeout-val)
Generic Function: realized? (x)

Returns true if a value has been produced for a promise or future, nil otherwise.

Package

clj-con.

Source

clj-con.lisp.

Methods
Method: realized? ((f future))
Method: realized? ((p promise))

5.1.4 Standalone methods

Method: print-object ((promise promise) stream)
Source

clj-con.lisp.

Method: print-object ((future future) stream)
Source

clj-con.lisp.


5.1.5 Structures

Structure: atom
Package

clj-con.

Source

atom.lisp.

Direct superclasses

structure-object.

Direct methods

deref.

Direct slots
Slot: cas-vector
Type

(array t 1)

Initform

#(nil)

Readers

atom-cas-vector.

Writers

(setf atom-cas-vector).

Structure: future

A future object returned by the ‘future‘ macro.

Package

clj-con.

Source

clj-con.lisp.

Direct superclasses

structure-object.

Direct methods
Direct slots
Slot: thread
Readers

future-thread.

Writers

(setf future-thread).

Slot: lock
Readers

future-lock.

Writers

(setf future-lock).

Slot: status
Readers

future-status.

Writers

(setf future-status).

Slot: promise
Readers

future-promise.

Writers

(setf future-promise).

Structure: promise

A promise object as created by the ‘promise‘ function.

Package

clj-con.

Source

clj-con.lisp.

Direct superclasses

structure-object.

Direct methods
Direct slots
Slot: condition-variable
Readers

promise-condition-variable.

Writers

(setf promise-condition-variable).

Slot: lock
Readers

promise-lock.

Writers

(setf promise-lock).

Slot: value
Readers

promise-value.

Writers

(setf promise-value).


5.2 Internals


5.2.1 Macros

Macro: with-future-lock (future &body body)

Execute body with the future locked.

Package

clj-con.

Source

clj-con.lisp.


5.2.2 Ordinary functions

Reader: atom-cas-vector (instance)
Writer: (setf atom-cas-vector) (instance)
Package

clj-con.

Source

atom.lisp.

Target Slot

cas-vector.

Function: copy-atom (instance)
Package

clj-con.

Source

atom.lisp.

Function: copy-future (instance)
Package

clj-con.

Source

clj-con.lisp.

Function: copy-promise (instance)
Package

clj-con.

Source

clj-con.lisp.

Reader: future-lock (instance)
Writer: (setf future-lock) (instance)
Package

clj-con.

Source

clj-con.lisp.

Target Slot

lock.

Reader: future-promise (instance)
Writer: (setf future-promise) (instance)
Package

clj-con.

Source

clj-con.lisp.

Target Slot

promise.

Reader: future-status (instance)
Writer: (setf future-status) (instance)
Package

clj-con.

Source

clj-con.lisp.

Target Slot

status.

Reader: future-thread (instance)
Writer: (setf future-thread) (instance)
Package

clj-con.

Source

clj-con.lisp.

Target Slot

thread.

Function: make-atom (&key cas-vector)
Package

clj-con.

Source

atom.lisp.

Function: make-future (&key thread lock status promise)
Package

clj-con.

Source

clj-con.lisp.

Function: make-promise (&key condition-variable lock value)
Package

clj-con.

Source

clj-con.lisp.

Reader: promise-condition-variable (instance)
Writer: (setf promise-condition-variable) (instance)
Package

clj-con.

Source

clj-con.lisp.

Target Slot

condition-variable.

Reader: promise-lock (instance)
Writer: (setf promise-lock) (instance)
Package

clj-con.

Source

clj-con.lisp.

Target Slot

lock.

Function: promise-p (object)
Package

clj-con.

Source

clj-con.lisp.

Function: promise-realized? (p)

True if value has been supplied, caller must lock before calling.

Package

clj-con.

Source

clj-con.lisp.

Reader: promise-value (instance)
Writer: (setf promise-value) (instance)
Package

clj-con.

Source

clj-con.lisp.

Target Slot

value.


5.2.3 Conditions

Condition: cancellation-exception

Signalled by deref (in the calling thread) when a a ‘future‘ thread was cancelled. Named for similarity to clojure/java behavior on deref.

Package

clj-con.

Source

clj-con.lisp.

Direct superclasses

error.

Condition: execution-exception

Signalled by deref (in the calling thread) when a ‘future‘ thread unwound its stack with an unhandled signal. Named for similarity to clojure/java behavior on deref.

Package

clj-con.

Source

clj-con.lisp.

Direct superclasses

error.

Condition: thread-interrupted

The thread-interrupted condition is signalled in ‘future‘ threads when ‘future-cancel‘ is called.

Package

clj-con.

Source

clj-con.lisp.

Direct superclasses

condition.


Appendix A Indexes


A.1 Concepts


A.2 Functions

Jump to:   (  
A   C   D   F   G   M   P   R   S   W  
Index Entry  Section

(
(setf atom-cas-vector): Private ordinary functions
(setf future-lock): Private ordinary functions
(setf future-promise): Private ordinary functions
(setf future-status): Private ordinary functions
(setf future-thread): Private ordinary functions
(setf promise-condition-variable): Private ordinary functions
(setf promise-lock): Private ordinary functions
(setf promise-value): Private ordinary functions

A
atom: Public ordinary functions
atom-cas-vector: Private ordinary functions
atom?: Public ordinary functions

C
compare-and-set!: Public ordinary functions
copy-atom: Private ordinary functions
copy-future: Private ordinary functions
copy-promise: Private ordinary functions

D
deliver: Public ordinary functions
deref: Public generic functions
deref: Public generic functions
deref: Public generic functions
deref: Public generic functions

F
Function, (setf atom-cas-vector): Private ordinary functions
Function, (setf future-lock): Private ordinary functions
Function, (setf future-promise): Private ordinary functions
Function, (setf future-status): Private ordinary functions
Function, (setf future-thread): Private ordinary functions
Function, (setf promise-condition-variable): Private ordinary functions
Function, (setf promise-lock): Private ordinary functions
Function, (setf promise-value): Private ordinary functions
Function, atom: Public ordinary functions
Function, atom-cas-vector: Private ordinary functions
Function, atom?: Public ordinary functions
Function, compare-and-set!: Public ordinary functions
Function, copy-atom: Private ordinary functions
Function, copy-future: Private ordinary functions
Function, copy-promise: Private ordinary functions
Function, deliver: Public ordinary functions
Function, future-call: Public ordinary functions
Function, future-cancel: Public ordinary functions
Function, future-cancelled?: Public ordinary functions
Function, future-done?: Public ordinary functions
Function, future-lock: Private ordinary functions
Function, future-promise: Private ordinary functions
Function, future-status: Private ordinary functions
Function, future-thread: Private ordinary functions
Function, future?: Public ordinary functions
Function, make-atom: Private ordinary functions
Function, make-future: Private ordinary functions
Function, make-promise: Private ordinary functions
Function, promise: Public ordinary functions
Function, promise-condition-variable: Private ordinary functions
Function, promise-lock: Private ordinary functions
Function, promise-p: Private ordinary functions
Function, promise-realized?: Private ordinary functions
Function, promise-value: Private ordinary functions
Function, reset!: Public ordinary functions
Function, reset-vals!: Public ordinary functions
Function, swap!: Public ordinary functions
Function, swap-vals!: Public ordinary functions
future: Public macros
future-call: Public ordinary functions
future-cancel: Public ordinary functions
future-cancelled?: Public ordinary functions
future-done?: Public ordinary functions
future-lock: Private ordinary functions
future-promise: Private ordinary functions
future-status: Private ordinary functions
future-thread: Private ordinary functions
future?: Public ordinary functions

G
Generic Function, deref: Public generic functions
Generic Function, realized?: Public generic functions

M
Macro, future: Public macros
Macro, with-future-lock: Private macros
make-atom: Private ordinary functions
make-future: Private ordinary functions
make-promise: Private ordinary functions
Method, deref: Public generic functions
Method, deref: Public generic functions
Method, deref: Public generic functions
Method, print-object: Public standalone methods
Method, print-object: Public standalone methods
Method, realized?: Public generic functions
Method, realized?: Public generic functions

P
print-object: Public standalone methods
print-object: Public standalone methods
promise: Public ordinary functions
promise-condition-variable: Private ordinary functions
promise-lock: Private ordinary functions
promise-p: Private ordinary functions
promise-realized?: Private ordinary functions
promise-value: Private ordinary functions

R
realized?: Public generic functions
realized?: Public generic functions
realized?: Public generic functions
reset!: Public ordinary functions
reset-vals!: Public ordinary functions

S
swap!: Public ordinary functions
swap-vals!: Public ordinary functions

W
with-future-lock: Private macros