thread-utils
TOC »
- thread-utils
- Documentation
- 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
- Usage
- thread-reaper-shutdown?
- thread-reap!
- zombie-threads
- 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!
- SRFI-18 Barrier
- Thread Utilities
- Bugs & Limitations
- Notes
- Requirements
- Author
- Repository
- Version history
- License
Documentation
SRFI 18 related utility routines; some CHICKEN specific.
Thread Utilities
Usage
(import thread-utils)
print-exception-error
- print-exception-error EXN #!optional THREAD PORT HEADERprocedure
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). The default for HEADER is the "\n\tThread call history:\n".
print-exception-warning
- print-exception-warning EXN #!optional THREAD PORT HEADERprocedure
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). The default for HEADER is the "\n\tThread call history:\n".
thread-warning-message
- thread-warning-message THREADprocedure
Returns the string "Warning (<THREAD>): ".
thread-timeout?
check-timeout
error-timeout
- thread-timeout? OBJECTprocedure
- check-timeout LOCATION OBJECT #!optional ARGUMENT-NAMEprocedure
- error-timeout LOCATION OBJECT #!optional ARGUMENT-NAMEprocedure
Is the OBJECT a thread-timeout object? A thread-timeout is #f, a number, or a SRFI 18 time object.
make-thread-timeout
- make-thread-timeout OFFSET #!optional BASEprocedure
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
- check-thread LOCATION OBJECT #!optional ARGUMENT-NAMEprocedure
- error-thread LOCATION OBJECT #!optional ARGUMENT-NAMEprocedure
Type checking for thread.
thread-created?
thread-ready?
thread-running?
thread-blocked?
thread-suspended?
thread-sleeping?
thread-terminated?
thread-dead?
- thread-created? THREADprocedure
- thread-ready? THREADprocedure
- thread-running? THREADprocedure
- thread-blocked? THREADprocedure
- thread-suspended? THREADprocedure
- thread-sleeping? THREADprocedure
- thread-terminated? THREADprocedure
- thread-dead? THREADprocedure
Is the THREAD in the indicated state?
thread-obstructed?
- thread-obstructed? THREADprocedure
Is the THREAD blocked or sleeping?
thread-state=?
- thread-state=? THREAD TOKENprocedure
Does the state token of the THREAD equal the supplied TOKEN.
thread-blocked-for-termination?
thread-blocked-for-io?
- thread-blocked-for-io? THREADprocedure
thread-blocked-for-timeout?
- thread-blocked-for-timeout? THREADprocedure
Is the THREAD in the indicated blocking state?
thread-unblock!
- thread-unblock! THREADprocedure
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
- thread-thunk THREADprocedure
thread-result-list
- thread-result-list THREADprocedure
thread-block-timeout
- thread-block-timeout THREADprocedure
thread-state-buffer
- thread-state-buffer THREADprocedure
Returns the THREAD's STATE-BUFFER.
thread-end-exception
- thread-end-exception THREADprocedure
thread-owned-mutexes
- thread-owned-mutexes THREADprocedure
thread-block-object
- thread-block-object THREADprocedure
thread-recipients
- thread-recipients THREADprocedure
thread-block-object-of-recipient?
- thread-block-object-of-recipient? THREADprocedure
Is THREAD a recipient of itself?
thread-dynamic-winds
- thread-dynamic-winds THREADprocedure
thread-standard-input
- thread-standard-input THREADprocedure
thread-standard-output
- thread-standard-output THREADprocedure
thread-standard-error
- thread-standard-error THREADprocedure
thread-default-exception-handler
thread-current-parameter-vector
Thread Reaper
Allows a thread to be joined to the primordial thread asynchronously.
Usage
(import thread-reaper)
thread-reaper-shutdown?
- thread-reaper-shutdown?procedure
thread-reap!
- thread-reap! THREADprocedure
Queues the supplied THREAD for reaping.
zombie-threads
- zombie-threadsprocedure
Returns the threads which could not be reaped, by timing out every retry.
thread-reaper-stop!
- thread-reaper-stop!procedure
Processes any threads queued for reaping and terminates the reaper.
thread-reaper-timeout
thread-reaper-timeout-set!
- thread-reaper-timeoutprocedure
- thread-reaper-timeout-set! SECONDSprocedure
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!
- thread-reaper-retriesprocedure
- thread-reaper-retries-set! SECONDSprocedure
Gets and sets the number of attempts to wait for a thread to quit.
Default is 1.
thread-reaper-greedy
thread-reaper-greedy-set!
- thread-reaper-greedyprocedure
- thread-reaper-greedy-set! FLAGprocedure
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!
- thread-reaper-wait-secondsprocedure
- thread-reaper-wait-seconds-set! SECONDSprocedure
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!
- thread-reaper-quantumprocedure
- thread-reaper-quantum-set! MILLISECONDSprocedure
Gets and sets the time-slice for the reaper.
Default is 2500.
Is the reaper shutting down?
SRFI-18 Barrier
Thread synchronization object.
Usage
(import (srfi-18 barrier))
make-barrier
- make-barrier #!optional LIMIT NAMEprocedure
Create and return a thread barrier.
- LIMIT
- fixnum : number of thread waiting before barrier "lifted", default 1.
- NAME
- * : object name, default #f.
barrier?
check-barrier
error-barrier
- barrier? OBJprocedure
Is OBJ a SRFI-18 barrier?
- check-barrier LOC OBJ #!rest NAMprocedure
- error-barrier LOC OBJ #!rest NAMprocedure
barrier-count
- barrier-count BARprocedure
Returns number of threads waiting on barrier BAR.
barrier-limit
- barrier-limit BARprocedure
Returns maximum number of threads waiting on barrier BAR.
barrier-name
- barrier-name BARprocedure
Returns name of barrier BAR.
barrier-specific
- barrier-specific BARprocedure
Returns the specific of barrier BAR.
barrier-specific-set!
- barrier-specific-set! BAR OBJprocedure
Sets the specific of barrier BAR.
barrier-state
- barrier-state BARprocedure
Returns the state of barrier BAR; see SRFI-18 mutex-state.
barrier-wait
- barrier-wait BAR #!optional TIMOUTprocedure
Synchronize calling thread at the barrier BAR. The calling thread will block until the barrier-limit number of threads have called barrier-wait on barrier BAR.
Returns #t, and #f otherwise, to the invoking thread when the barrier is "lifted".
- BAR
- barrier : barrier to wait "behind."
- TIMOUT
- (or false real time) : timeout to abandon wait.
Bugs & Limitations
- thread-reaper-timeout & thread-reaper-retries are poorly named.
Notes
- All numbers are as defined by the Chicken core.
Requirements
srfi-18 queues synch miscmacros moremacros record-variants check-errors
Author
Repository
This egg is hosted on the CHICKEN Subversion repository:
https://anonymous@code.call-cc.org/svn/chicken-eggs/release/5/thread-utils
If you want to check out the source code repository of this egg and you are not familiar with Subversion, see this page.
Version history
- 2.2.5
- Fix barrier-name.
- 2.2.4
- Fix barrier-specific type.
- 2.2.3
- Fix timeout type; see barrier-wait TIMOUT argument.
- 2.2.2
- Fix barrier-name.
- 2.2.1
- .
- 2.2.0
- Add (srfi-18 barrier).
- 2.1.2
- .
- 2.1.1
- .
- 2.1.0
- Add zombie concept.
- 2.0.0
- C5 port.
- 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-2022 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.