Wiki
Download
Manual
Eggs
API
Tests
Bugs
show
edit
history
You can edit this page using
wiki syntax
for markup.
Article contents:
== Outdated egg! This is an egg for CHICKEN 3, the unsupported old release. You're almost certainly looking for [[/eggref/4/mailbox|the CHICKEN 4 version of this egg]], if it exists. If it does not exist, there may be equivalent functionality provided by another egg; have a look at the [[https://wiki.call-cc.org/chicken-projects/egg-index-4.html|egg index]]. Otherwise, please consider porting this egg to the current version of CHICKEN. [[tags: egg]] == mailbox [[toc:]] === Description Thread-safe queues with timeout === Author [[/users/felix winkelmann|felix winkelmann]] and [[Kon Lovett]] === Requirements None === Download [[http://code.call-cc.org/legacy-eggs/3/mailbox.egg|mailbox.egg]] === Documentation <procedure>(make-mailbox [NAME])</procedure> Returns a new mailbox object. {{NAME}} is an optional name for this mailbox and defaults to some {{gensym}}'d symbol. <procedure>(mailbox? OBJECT)</procedure> Is the {{OBJECT}} a mailbox? <procedure>(mailbox-name MAILBOX)</procedure> Returns the name of the {{MAILBOX}}. <procedure>(mailbox-empty? MAILBOX)</procedure> If there is no data waiting to be transmitted in the {{MAILBOX}}, then this procedure returns {{#t}}, otherwise it returns {{#f}}. <procedure>(mailbox-timeout-exception? OBJECT)</procedure> Is the {{OBJECT}} a mailbox timeout exception? A mailbox timeout exception is a composite condition of {{'exn}}, {{'mailbox}}, and {{'timeout}}, with properties of {{'location}} and {{'arguments}}. <procedure>(mailbox-send! MAILBOX X)</procedure> Stores the data object {{X}}. If any threads exist that are waiting for input on {{MAILBOX}}, the execution of the first one will be resumed. The data will be read out of a mailbox in the same order in which is written in (in FIFO manner). <procedure>(mailbox-receive! MAILBOX [TIMEOUT-SECONDS [TIMEOUT-DEFAULT]])</procedure> If there is any data in the {{MAILBOX}}, then the first object will be removed and returned as the result. If the mailbox is currently empty, the current thread will suspended until data is available. Should a timeout be specified and occur the {{TIMEOUT-DEFAULT}} will be returned. Otherwise a mailbox timeout exception will be signaled for the calling thread. The {{TIMEOUT-DEFAULT}} value cannot be {{(void)}}. <procedure>(mailbox-wait! MAILBOX [TIMEOUT-SECONDS])</procedure> Similar to {{mailbox-receive!}}, but does not remove the received result from the queue of pending data. Should a timeout be specified and occur a mailbox timeout exception will be signaled for the calling thread. <procedure>(mailbox-push-back! MAILBOX ITEM)</procedure> Pushes an item into the first position of a mailbox. <procedure>(mailbox-push-back-list! MAILBOX LIST)</procedure> Pushes the items in item-list back into the mailbox, so that {{(car LIST)}} becomes the next receivable item. <procedure>(make-mailbox-cursor MAILBOX)</procedure> Returns an object which can enumerate a mailbox. Multiple cursors can scan, and mutate, the same mailbox. <procedure>(mailbox-cursor? OBJECT)</procedure> Is the {{OBJECT}} a {{mailbox-cursor}}? <procedure>(mailbox-cursor-mailbox MAILBOX-CURSOR)</procedure> Returns the mailbox object associated with the mailbox cursor. <procedure>(mailbox-cursor-next MAILBOX-CURSOR [TIMEOUT-SECONDS [TIMEOUT-DEFAULT]])</procedure> Returns the next object in the mailbox queue, waiting if necessary. The mailbox queue is scanned from oldest to newest. Should a timeout be specified and occur the {{TIMEOUT-DEFAULT}} will be returned. Otherwise a mailbox timeout exception will be signaled for the calling thread. The {{TIMEOUT-DEFAULT}} value cannot be {{(void)}}. <procedure>(mailbox-cursor-rewind MAILBOX-CURSOR)</procedure> Position the cursor at the oldest message in the mailbox. <procedure>(mailbox-cursor-extract-and-rewind MAILBOX-CURSOR)</procedure> Remove from the associated mailbox queue the last object returned by {{mailbox-cursor-next}} and position the cursor at the oldest message in the mailbox. The extraction is not performed without a previous call to {{mailbox-cursor-next}}. === Example <enscript highlight="scheme"> (require-extension mailbox) (define (consumer ch) (make-thread (lambda () (let loop () (print (current-thread) ": reading " (mailbox-receive! ch)) (loop) ) ) ) ) (define ch (make-mailbox)) (thread-start! (consumer ch)) (for-each (lambda (x) (print (current-thread) ": writing " x) (mailbox-send! ch x) ) '(33 44 55 hello) ) </enscript> === Changelog * 1.2 * 1.1 Renamed to mailbox (and made old mailbox implementation obsolete) * 1.0 Initial release === License Copyright (c) 2003, Felix L. Winkelmann All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Description of your changes:
I would like to authenticate
Authentication
Username:
Password:
Spam control
What do you get when you subtract 22 from 15?