Outdated egg!
This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for the CHICKEN 5 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 egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.
thread-utils
- Outdated egg!
- thread-utils
- Documentation
- Thread Reaper
- Usage
- thread-reaper-shutdown?
- thread-reap!
- thread-reaper-stop!
- thread-reaper-timeout
- thread-reaper-timeout-set!
- thread-reaper-retries
- thread-reaper-retries-set!
- thread-reaper-greedy
- thread-reaper-greedy-set!
- thread-reaper-wait-seconds
- thread-reaper-wait-seconds-set!
- thread-reaper-quantum
- thread-reaper-quantum-set!
- Thread Utilities
- Usage
- print-exception-error
- print-exception-warning
- thread-warning-message
- thread-timeout?
- check-timeout
- error-timeout
- make-thread-timeout
- check-thread
- error-thread
- thread-created?
- thread-ready?
- thread-running?
- thread-blocked?
- thread-suspended?
- thread-sleeping?
- thread-terminated?
- thread-dead?
- thread-obstructed?
- thread-state=?
- thread-blocked-for-termination?
- thread-blocked-for-io?
- thread-blocked-for-timeout?
- thread-unblock!
- thread-thunk
- thread-result-list
- thread-block-timeout
- thread-state-buffer
- thread-end-exception
- thread-owned-mutexes
- thread-block-object
- thread-recipients
- thread-block-object-of-recipient?
- thread-dynamic-winds
- thread-standard-input
- thread-standard-output
- thread-standard-error
- thread-default-exception-handler
- thread-current-parameter-vector
- Thread Reaper
- Bugs & Limitations
- Notes
- Requirements
- Author
- Version history
- License
Documentation
Some SRFI 18 related utility routines.
Rather Chicken centric.
Thread Reaper
Allows a thread to be joined to the primordial thread asynchronously.
Usage
(require-extension thread-reaper)
thread-reaper-shutdown?
[procedure] (thread-reaper-shutdown?) => booleanthread-reap!
[procedure] (thread-reap! THREAD)Queues the supplied THREAD for reaping.
thread-reaper-stop!
[procedure] (thread-reaper-stop!)Processes any threads queued for reaping and terminates the reaper.
thread-reaper-timeout
thread-reaper-timeout-set!
[procedure] (thread-reaper-timeout) => (or #f number)[procedure] (thread-reaper-timeout-set! SECONDS)
Gets and sets the number of seconds to wait for a thread to quit. The default is #f or wait till termination. Should threads submitted to the reaper be known to "run off with the cpu" then something other than wait forever is warranted.
thread-reaper-retries
thread-reaper-retries-set!
[procedure] (thread-reaper-retries) => fixnum[procedure] (thread-reaper-retries-set! SECONDS)
Gets and sets the number of attempts to wait for a thread to quit.
Default is 1.
thread-reaper-greedy
thread-reaper-greedy-set!
[procedure] (thread-reaper-greedy) => boolean[procedure] (thread-reaper-greedy-set! FLAG)
Gets and sets the reaper greedy mode. When greedy the queue is exhausted whenever possible. Otherwise only one queue item is processed per time-slice.
Default is #f.
thread-reaper-wait-seconds
thread-reaper-wait-seconds-set!
[procedure] (thread-reaper-wait-seconds) => (or #f number)[procedure] (thread-reaper-wait-seconds-set! SECONDS)
Gets and sets the number of seconds to wait before another attempt by the reaper. The default is 1.0.
thread-reaper-quantum
thread-reaper-quantum-set!
[procedure] (thread-reaper-quantum) => number[procedure] (thread-reaper-quantum-set! MILLISECONDS)
Gets and sets the time-slice for the reaper.
Default is 2500.
Is the reaper shutting down?
Thread Utilities
Usage
(require-extension thread-utils)
print-exception-error
[procedure] (print-exception-error EXN [THREAD [PORT]])Prints the error EXN and the current call chain. The message header is supplied by thread-warning-message. This routine duplicates the uncaught exception in a thread handling behavior of Chicken. Useful for caught exceptions that cannot in fact be handled.
The EXN is a condition or any other object. The default for THREAD is the (current-thread). The default for PORT is the (current-error-port).
print-exception-warning
[procedure] (print-exception-warning EXN [THREAD [PORT]])Invokes print-exception-error when warnings are enabled.
The EXN is a condition or any other object. The default for THREAD is the (current-thread). The default for PORT is the (current-error-port).
thread-warning-message
[procedure] (thread-warning-message THREAD) => stringReturns the string "Warning (<THREAD>): ".
thread-timeout?
check-timeout
error-timeout
[procedure] (thread-timeout? OBJECT) => boolean[procedure] (check-timeout LOCATION OBJECT [ARGUMENT-NAME]) => (or #f time number)
[procedure] (error-timeout LOCATION OBJECT [ARGUMENT-NAME])
Is the OBJECT a thread-timeout object? A thread-timeout is #f, a number, or a SRFI 18 time object.
make-thread-timeout
[procedure] (make-thread-timeout OFFSET [BASE]) => (or #f time)Returns the SRFI 18 time object representing the OFFSET + BASE. The BASE is a thread-timeout object with default (current-time).
Should OFFSET be #f or a time object the BASE is ignored and OFFSET is returned. Assumes an absolute OFFSET indicates a timeout already calculated.
check-thread
error-thread
[procedure] (check-thread LOCATION OBJECT [ARGUMENT-NAME]) => thread[procedure] (error-thread LOCATION OBJECT [ARGUMENT-NAME])
Type checking for thread.
thread-created?
thread-ready?
thread-running?
thread-blocked?
thread-suspended?
thread-sleeping?
thread-terminated?
thread-dead?
[procedure] (thread-created? THREAD) => boolean[procedure] (thread-ready? THREAD) => boolean
[procedure] (thread-running? THREAD) => boolean
[procedure] (thread-blocked? THREAD) => boolean
[procedure] (thread-suspended? THREAD) => boolean
[procedure] (thread-sleeping? THREAD) => boolean
[procedure] (thread-terminated? THREAD) => boolean
[procedure] (thread-dead? THREAD) => boolean
Is the THREAD in the indicated state?
thread-obstructed?
[procedure] (thread-obstructed? THREAD) => booleanIs the THREAD blocked or sleeping?
thread-state=?
[procedure] (thread-state=? THREAD TOKEN) => booleanDoes the state token of the THREAD equal the supplied TOKEN.
thread-blocked-for-termination?
[procedure] (thread-blocked-for-termination? THREAD) => booleanthread-blocked-for-io?
[procedure] (thread-blocked-for-io? THREAD) => booleanthread-blocked-for-timeout?
[procedure] (thread-blocked-for-timeout? THREAD) => booleanIs the THREAD in the indicated blocking state?
thread-unblock!
[procedure] (thread-unblock! THREAD)Attempts to cleanly unblock the THREAD.
Currently only threads blocked for timeout can be unblocked. Threads blocked for any other reason are ignored.
thread-thunk
[procedure] (thread-thunk THREAD) => procedurethread-result-list
[procedure] (thread-result-list THREAD) => (or #f list)thread-block-timeout
[procedure] (thread-block-timeout THREAD) => (or #f float)thread-state-buffer
[procedure] (thread-state-buffer THREAD) => state-bufferReturns the THREAD's STATE-BUFFER.
thread-end-exception
[procedure] (thread-end-exception THREAD) => *thread-owned-mutexes
[procedure] (thread-owned-mutexes THREAD) => listthread-block-object
[procedure] (thread-block-object THREAD) => *thread-recipients
[procedure] (thread-recipients THREAD) => listthread-block-object-of-recipient?
[procedure] (thread-block-object-of-recipient? THREAD) => booleanIs THREAD a recipient of itself?
thread-dynamic-winds
[procedure] (thread-dynamic-winds THREAD) => listthread-standard-input
[procedure] (thread-standard-input THREAD) => portthread-standard-output
[procedure] (thread-standard-output THREAD) => portthread-standard-error
[procedure] (thread-standard-error THREAD) => portthread-default-exception-handler
[procedure] (thread-default-exception-handler THREAD) => procedurethread-current-parameter-vector
[procedure] (thread-current-parameter-vector THREAD) => vectorBugs & Limitations
- thread-reaper-timeout & thread-reaper-retries are poorly named.
Notes
- All numbers are as defined by the Chicken core.
Requirements
miscmacros synch thread-utils record-variants check-errors setup-helper
Author
Version history
- 1.2.0
- Add reaper state setters.
- 1.1.0
- Add thread-... & *thread-... getters. Deprecated thread-blocked?/.... Added thread-blocked-for...?.
- 1.0.2
- "Fix" for ticket #981. Added thread-reaper-wait-seconds.
- 1.0.1
- Use compiled setup-helper (& un-hide).
- 1.0.0
- Moved from srfi-27 into own extension.
License
Copyright (C) 2010-2018 Kon Lovett. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the Software), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED ASIS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.