You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.9 KiB

6 years ago
=== Go-like channels for atomically passing information between threads, and some other async stuff. ===
--- Channels ---
6 years ago
(channel:make-channel) ; make new channel
(channel:make-channel 2) ; make new channel with max size of 2 (untested)
6 years ago
(channel:-> chan item) ; send item to channel
(channel:<- chan) ; receive from channel (values item is-not-closed), blocks until there is one
(channel:release chan) ; close channel
(channel:closed chan) ; is channel closed
(channel:¬closed chan) ; (not (closed chan))
6 years ago
--- Tools ---
(async-tools:async &body body) ; Run body asyncrounously. Returns promise that can be passed to async-tools:wait() to join thread then return the last value of `body'.
(async-tools:wait promise) ; Wait on promise, return it's value and T if the thread exited without being killed.
(async-tools:kill promise) ; Kill this thread
(async-tools:value promise) ; Return value of this promise, like wait but does not block. returns (values nil nil) if the thread has not exited yet;
See `async-tools.lisp' for more info.
(async-tools:enable-reader) ; Enable reader macro $(form) for running form as async. Like, $(print 'hi) -> (async (print 'hi))
--- Signalling ---
6 years ago
(dispatcher:make-dispatcher) ; make dispatcher
6 years ago
(dispatcher:hook disp name lambda) ; add hook
(dispatcher:sig name (optional value)) ; signal name in parallel
(dispatcher:sig-serial name (optional value)) ; signal name in serial
--- Atomic operations ---
(box:make &optional value) ; make a box with default value
(box:<- box) ; get value atomically
(box:-> box value) ; set value atomically
(box:<-! box) ; get value without lock
(box:->! box vlaue) ; set value without lock
(setf (box:@ box) value) ; set value atomically
(box:--> box &body things) ; do (progn ,@things) with lock held then set value to box
(box:<-- box &body things) ; do (progn ,@things) with lock held. return value of box.
; these two macros flet functions (box:<-) and (box:-> thing) to get&set from box while lock is held.