((section 2 "Outdated egg!" (p "This is an egg for CHICKEN 4, the unsupported old release.  You're almost certainly looking for " (int-link "/eggref/5/mailbox-threads" "the CHICKEN 5 version of this egg") ", if it exists.") (p "If it does not exist, there may be equivalent functionality provided by another egg; have a look at the " (link "https://wiki.call-cc.org/chicken-projects/egg-index-5.html" "egg index") ". Otherwise, please consider porting this egg to the current version of CHICKEN.") (toc) (tags "eggs")) (section 2 "mailbox-threads" (p "This extension extends srfi-18 in a way that mailboxes are attached to each thread. This makes sending messages to threads possible.") (section 3 "Documentation" (section 4 "interface" (def (sig (procedure "(current-thread)" (id current-thread))) (p "Returns the current thread as an object, converting it to a mailbox-thread if necessary.")) (def (sig (procedure "(make-thread THUNK [NAME])" (id make-thread))) (p "Creates a mailbox thread that will run " (tt "THUNK") " and names it after " (tt "NAME") ".")) (def (sig (procedure "(thread-specific-set! THREAD OBJECT)" (id thread-specific-set!))) (p "Like srfi-18's procedure this one sets the thread-specific of " (tt "THREAD") " to " (tt "OBJECT") ".")) (def (sig (procedure "(thread-specific THREAD)" (id thread-specific))) (p "Returns the thread-specific object of " (tt "THREAD") ".")) (def (sig (procedure "(thread-send THREAD MSG)" (id thread-send))) (p "Sends a " (tt "MSG") " to " (tt "THREAD") "'s mailbox.")) (def (sig (procedure "(thread-start! THREAD)" (id thread-start!))) (p "Starts " (tt "THREAD") " if it is a thread, if " (tt "THREAD") " is a procedure " (tt "make-thread") " is called first.")) (def (sig (procedure "(thread? THREAD)" (id thread?))) (p "Returns " (tt "#t") " if " (tt "THREAD") " is a mailbox-thread.")) (def (sig (procedure "(thread-receive [TIMEOUT [DEFAULT]])" (id thread-receive))) (p "Returns the next message of the current thread's mailbox. This will block until a message arrives unless " (tt "TIMEOUT") " is given (for definition of time units see " (tt "mailbox-receive!") " procedure). If the timeout is reached " (tt "DEFAULT") " is returned.")) (def (sig (procedure "thread-mailbox-next" (id thread-mailbox-next)) (procedure "thread-mailbox-rewind" (id thread-mailbox-rewind)) (procedure "thread-mailbox-extract-and-rewind" (id thread-mailbox-extract-and-rewind))) (p "Those work like their SRFI-18's brothers."))) (section 4 "implementation" (p "The thread's mailboxes are stored as the usual SRFI-18 thread-specific. To be able to tell mailbox-threads apart from SRFI-18 threads a tag will be added, so the specific looks like this:") (p (tt "('mboxthread specific mbox mbox-cursor)")) (p "Therefore the thread-specific and thread-specific-set! procedures are redefined in this module.") (p "Some procedures will add these structures silently to existing threads, " (tt "current-thread") " for example."))) (section 3 "Example" (highlight scheme "(use mailbox-threads)\n\n(define (t1-thunk)\n   (let ((msg (thread-receive 999)))\n      (if (equal? msg 'quit)\n\n          (begin (print \"Bye Ma!\")\n          (thread-terminate! (current-thread)))\n\n          (begin\n           (print msg)\n          (t1-thunk)))))\n\n(define t1 (make-thread t1-thunk 't1))\n\n(thread-send t1 \"Hi there!\")\n(thread-start! t1)\n(thread-send t1 \"still awake!\")\n(thread-send t1 \"Look Ma! Threads with mailboxes!\")\n;(thread-send t1 'quit)\n(thread-start! (lambda () (thread-send t1 \"hi from two\")))\n(thread-specific t1)\n(thread-specific-set! t1 \"hi\")\n(thread-specific t1)\n")) (section 3 "Requirements" (p (int-link "/eggref/4/mailbox") ", " (int-link "/man/4/Unit srfi-18")))) (section 2 "Author" (p (int-link "/users/christian kellermann" "christian kellermann"))) (section 2 "License" (pre "Copyright (c) 2009, The CHICKEN Team\nAll rights reserved.") (pre "Redistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are met:\n\n  Redistributions of source code must retain the above copyright notice,\n    this list of conditions and the following disclaimer. \n  Redistributions in binary form must reproduce the above copyright notice,\n    this list of conditions and the following disclaimer in the\n    documentation and/or other materials provided with the distribution.\n  Neither the name of the author nor the names of its contributors may be\n    used to endorse or promote products derived from this software without\n    specific prior written permission.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\nAND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\nIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\nARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE\nLIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\nCONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\nSUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\nINTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\nCONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\nARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\nPOSSIBILITY OF SUCH DAMAGE.")) (section 2 "Version History" (dl (dt "1.4 ; Export current-thread procedure, found by megane") (dt "1.3 ; Fix returning and using a unspecified value. Thanks to the new scrutinizer.") (dt "1.2") (dd "Fix author entry, thanks to " (int-link "/users/peter-bex" "Peter Bex") ".") (dt "1.0") (dd "Initial release"))))