Common Lisp Package: LPARALLEL.THREAD-UTIL

(private) Thread utilities.

README:

FUNCTION

Public

Undocumented

CONDITION-NOTIFY-AND-YIELD (CONDITION-VARIABLE)

CONDITION-WAIT (CONDITION-VARIABLE LOCK)

CURRENT-THREAD

DESTROY-THREAD (THREAD)

MAKE-CONDITION-VARIABLE (&KEY NAME)

MAKE-LOCK (&OPTIONAL NAME)

Private

ACQUIRE-LOCK (LOCK &OPTIONAL (WAIT-P T))

Acquire the lock LOCK for the calling thread. WAIT-P governs what happens if the lock is not available: if WAIT-P is true, the calling thread will wait until the lock is available and then acquire it; if WAIT-P is NIL, ACQUIRE-LOCK will return immediately. ACQUIRE-LOCK returns true if the lock was acquired and NIL otherwise. This specification does not define what happens if a thread attempts to acquire a lock that it already holds. For applications that require locks to be safe when acquired recursively, see instead MAKE-RECURSIVE-LOCK and friends.

CONDITION-NOTIFY (CONDITION-VARIABLE)

Notify at least one of the threads waiting for CONDITION-VARIABLE. It is implementation-dependent whether one or more than one (and possibly all) threads are woken, but if the implementation is capable of waking only a single thread (not all are) this is probably preferable for efficiency reasons. The order of wakeup is unspecified and does not necessarily relate to the order that the threads went to sleep in. CONDITION-NOTIFY has no useful return value. In an implementation that does not support multiple threads, it has no effect.

MAKE-THREAD (FUNCTION &KEY NAME (INITIAL-BINDINGS *DEFAULT-SPECIAL-BINDINGS*))

Creates and returns a thread named NAME, which will call the function FUNCTION with no arguments: when FUNCTION returns, the thread terminates. NAME defaults to "Anonymous thread" if unsupplied. On systems that do not support multi-threading, MAKE-THREAD will signal an error. The interaction between threads and dynamic variables is in some cases complex, and depends on whether the variable has only a global binding (as established by e.g. DEFVAR/DEFPARAMETER/top-level SETQ) or has been bound locally (e.g. with LET or LET*) in the calling thread. - Global bindings are shared between threads: the initial value of a global variable in the new thread will be the same as in the parent, and an assignment to such a variable in any thread will be visible to all threads in which the global binding is visible. - Local bindings, such as the ones introduced by INITIAL-BINDINGS, are local to the thread they are introduced in, except that - Local bindings in the the caller of MAKE-THREAD may or may not be shared with the new thread that it creates: this is implementation-defined. Portable code should not depend on particular behaviour in this case, nor should it assign to such variables without first rebinding them in the new thread.

RELEASE-LOCK (LOCK)

Release LOCK. It is an error to call this unless the lock has previously been acquired (and not released) by the same thread. If other threads are waiting for the lock, the ACQUIRE-LOCK call in one of them will now be able to continue. This function has no interesting return value.

MACRO

Public

Undocumented

CAS (PLACE OLD NEW &ENVIRONMENT ENV)

DEFINE-LOCKING-FN (NAME ARGS ARG-TYPES RETURN-TYPE LOCK &BODY BODY)

DEFINE-SIMPLE-LOCKING-FN (NAME ARGS ARG-TYPES RETURN-TYPE LOCK &BODY BODY)

WITH-LOCK-HELD ((PLACE) &BODY BODY)

WITH-LOCK-PREDICATE/NO-WAIT (LOCK PREDICATE &BODY BODY)

WITH-LOCK-PREDICATE/WAIT (LOCK PREDICATE &BODY BODY)

WITH-THREAD ((&KEY BINDINGS NAME) &BODY BODY)

Private

Undocumented

DEFINE-LOCKING-FN/BASE (NAME ARGS ARG-TYPES RETURN-TYPE LOCK-READER DEFUN/NO-LOCK ARG-TYPES/NO-LOCK RETURN-TYPE/NO-LOCK &BODY BODY)

WITH-ABORT-RESTART (&BODY BODY)

VARIABLE

Private

*DEFAULT-SPECIAL-BINDINGS*

This variable holds an alist associating special variable symbols to forms to evaluate. Special variables named in this list will be locally bound in the new thread before it begins executing user code. This variable may be rebound around calls to MAKE-THREAD to add/alter default bindings. The effect of mutating this list is undefined, but earlier forms take precedence over later forms for the same symbol, so defaults may be overridden by consing to the head of the list.