Next: sb-cover, Previous: sb-aclrepl, Up: Contributed Modules
Additional data structures, synchronization primitives and tools for
concurrent programming. Similiar to Java's java.util.concurrent
package.
sb-concurrency:queue is a lock-free, thread-safe FIFO queue
datatype.
The implementation is based on An Optimistic Approach to
Lock-Free FIFO Queues by Edya Ladan-Mozes and Nir Shavit.
Before SBCL 1.0.38, this implementation resided in its own contrib
(see sb-queue) which is still provided for backwards-compatibility
but which has since been deprecated.
enqueue can be used to add objects to a queue, and
dequeue retrieves items from a queue in FIFO order.
Class precedence list:
queue, structure-object, tLock-free thread safe queue.
Retrieves the oldest value in
queueand returns it as the primary value, andtas secondary value. If the queue is empty, returnsnilas both primary and secondary value.
Returns the contents of
queueas a list without removing them from thequeue. Mainly useful for manual examination of queue state.
Returns a new
queuewithnameand contents of theinitial-contentssequence enqueued.
Returns the number of objects in
queue. Mainly useful for manual examination of queue state, and inprint-objectmethods: inefficient as it walks the entire queue.
sb-concurrency:mailbox is a lock-free message queue where one
or multiple ends can send messages to one or multiple receivers. The
difference to Section sb-concurrency:queue is that the receiving
end may block until a message arrives.
The implementation is based on the Queue implementation above
(see Structure sb-concurrency:queue.)
send-message can be used to send a message to a mailbox, and
receive-message retrieves a message from a mailbox, or blocks
until a new message arrives. receive-message-no-hang is the
non-blocking variant.
Messages can be any object.
Class precedence list:
mailbox, structure-object, tMailbox aka message queue.
Returns a fresh list containing all the messages in the mailbox. Does not remove messages from the mailbox.
Returns the number of messages currently in the mailbox.
Returns true if
mailboxis currently empty,nilotherwise.
Returns a new
mailboxwith messages ininitial-contentsenqueued.
Removes the oldest message from
mailboxand returns it as the primary value. Ifmailboxis empty waits until a message arrives.
The non-blocking variant of
receive-message. Returns two values, the message removed frommailbox, and a flag specifying whether a message could be received.
Removes and returns all (or at most N) currently pending messages from
mailbox, or returnsnilif no messages are pending.Note: Concurrent threads may be snarfing messages during the run of this function, so even though
x,yappear right next to each other in the result, does not necessarily mean thatywas the message sent right afterx.