/usr/share/doc/chicken-bin/manual-html/Unit srfi-18.html is in chicken-bin 4.11.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 | <!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="manual.css" type="text/css" /></head>
<title>Chicken » Unit srfi-18</title>
<meta name="viewport" content="initial-scale=1" /></html>
<body>
<div id="body">
<div id="main">
<div id="toc">
<h2 class="toc">TOC »</h2>
<ul class="toc">
<li><a href="#sec:Unit_srfi-18">Unit srfi-18</a></li>
<li><a href="#sec:CHICKEN_implementation">CHICKEN implementation</a>
<ul>
<li><a href="#sec:Notes">Notes</a></li>
<li><a href="#sec:Procedures">Procedures</a></li></ul></li>
<li><a href="#sec:SRFI-18_specification">SRFI-18 specification</a>
<ul>
<li><a href="#sec:Background_information">Background information</a>
<ul>
<li><a href="#sec:Threads">Threads</a></li>
<li><a href="#sec:Mutexes">Mutexes</a></li>
<li><a href="#sec:Condition_variables">Condition variables</a></li>
<li><a href="#sec:Fairness">Fairness</a></li>
<li><a href="#sec:Memory_coherency_and_lack_of_atomicity">Memory coherency and lack of atomicity</a></li>
<li><a href="#sec:Dynamic_environments.2c_continuations_and_dynamic-wind">Dynamic environments, continuations and <tt>dynamic-wind</tt></a></li>
<li><a href="#sec:Time_objects_and_timeouts">Time objects and timeouts</a></li>
<li><a href="#sec:Primitives_and_exceptions">Primitives and exceptions</a></li>
<li><a href="#sec:Primordial_thread">Primordial thread</a></li></ul></li>
<li><a href="#sec:Procedures">Procedures</a></li></ul></li></ul></div><h2 id="sec:Unit_srfi-18"><a href="#sec:Unit_srfi-18">Unit srfi-18</a></h2><p>A multithreading package, largely following the specification of <a href="http://srfi.schemers.org/srfi-18/srfi-18.html">SRFI-18</a>. This document contains the core of the SRFI-18 documentation as well as information on CHICKEN deviations from the spec.</p><p>The threads implemented in CHICKEN are so called "green" threads, based on first-class continuations. Native threads that map directly to the threads provided by the operating system are not supported. The advantage of this is that threads are very lightweight and somewhat larger degree of determinism. The disadvantage is that execution of Scheme code on multiple processor cores is not available.</p><p>SRFI-18 defines the following multithreading datatypes:</p><ul><li>Thread </li>
<li>Mutex </li>
<li>Condition variable </li>
<li>Time </li>
</ul>
<p>It also defines a mechanism to handle exceptions and some multithreading exception datatypes.</p><h2 id="sec:CHICKEN_implementation"><a href="#sec:CHICKEN_implementation">CHICKEN implementation</a></h2><h3 id="sec:Notes"><a href="#sec:Notes">Notes</a></h3><ul><li><tt>thread-start!</tt> accepts a thunk (a zero argument procedure) as argument, which is equivalent to <tt>(thread-start! (make-thread THUNK))</tt>.</li>
<li><tt>thread-sleep!</tt> accepts a seconds real number value in addition to a time object.</li>
<li>When an uncaught exception (i.e. an error) is signalled in a thread other than the primordial thread and warnings are enabled (see: <tt>enable-warnings</tt>, then a warning message is written to the port that is the value of <tt>(current-error-port)</tt>.</li>
<li>Blocking I/O will block all threads, except for some socket operations (see the section about the <tt>tcp</tt> unit). An exception is the read-eval-print loop on UNIX platforms: waiting for input will not block other threads, provided the current input port reads input from a console.</li>
<li>It is generally not a good idea for one thread to call a continuation created by another thread, if <tt>dynamic-wind</tt> is involved.</li>
<li>When more than one thread compete for the current time-slice, the thread that was waiting first will become the next runnable thread.</li>
<li>The dynamic environment of a thread consists of the following state:<ul><li>The current input-, output- and error-port</li>
<li>The current exception handler</li>
<li>The values of all current parameters (created by <tt>make-parameter</tt>)</li>
<li>Any pending <tt>dynamic-wind</tt> thunks.</li>
</ul>
</li>
<li>When an error is triggered inside the execution context of a thread, the default exception-handler will simply terminate the thread (and store the error condition for later use). Pending <tt>dynamic-wind</tt> thunks will <i>not</i> be invoked. Use a custom exception handler for the thread in that case.</li>
</ul>
<h3 id="sec:Procedures"><a href="#sec:Procedures">Procedures</a></h3><p>The following procedures are provided in addition to the procedures defined in SRFI-18.</p><dl class="defsig"><dt class="defsig" id="def:thread-signal.21"><span class="sig"><tt>(thread-signal! THREAD X)</tt></span> <span class="type">procedure</span></dt>
<dd class="defsig"><p>This will cause <tt>THREAD</tt> to signal the condition <tt>X</tt> once it is scheduled for execution. After signalling the condition, the thread continues with its normal execution.</p></dd>
</dl>
<dl class="defsig"><dt class="defsig" id="def:thread-quantum"><span class="sig"><tt>(thread-quantum THREAD)</tt></span> <span class="type">procedure</span></dt>
<dd class="defsig"><p>Returns the quantum of <tt>THREAD</tt>, which is an exact integer specifying the approximate time-slice of the thread in milliseconds.</p></dd>
</dl>
<dl class="defsig"><dt class="defsig" id="def:thread-quantum-set.21"><span class="sig"><tt>(thread-quantum-set! THREAD QUANTUM)</tt></span> <span class="type">procedure</span></dt>
<dd class="defsig"><p>Sets the quantum of <tt>THREAD</tt> to <tt>QUANTUM</tt>.</p></dd>
</dl>
<dl class="defsig"><dt class="defsig" id="def:thread-suspend.21"><span class="sig"><tt>(thread-suspend! THREAD)</tt></span> <span class="type">procedure</span></dt>
<dd class="defsig"><p>Suspends the execution of <tt>THREAD</tt> until resumed.</p></dd>
</dl>
<dl class="defsig"><dt class="defsig" id="def:thread-resume.21"><span class="sig"><tt>(thread-resume! THREAD)</tt></span> <span class="type">procedure</span></dt>
<dd class="defsig"><p>Readies the suspended thread <tt>THREAD</tt>.</p></dd>
</dl>
<dl class="defsig"><dt class="defsig" id="def:thread-wait-for-i.2fo.21"><span class="sig"><tt>(thread-wait-for-i/o! FD [MODE])</tt></span> <span class="type">procedure</span></dt>
<dd class="defsig"><p>Suspends the current thread until input (<tt>MODE</tt> is <tt>#:input</tt>), output (<tt>MODE</tt> is <tt>#:output</tt>) or both (<tt>MODE</tt> is <tt>#:all</tt>) is available. <tt>FD</tt> should be a file-descriptor (not a port!) open for input or output, respectively.</p></dd>
</dl>
<dl class="defsig"><dt class="defsig" id="def:thread-state"><span class="sig"><tt>(thread-state thread)</tt></span> <span class="type">procedure</span></dt>
<dd class="defsig"><p>Returns information about the state of the <tt>thread</tt>. The possible results are:</p><ul><li><b>symbol <tt>created</tt></b>: the <tt>thread</tt> is in the created state </li>
<li><b>symbol <tt>ready</tt></b>: the <tt>thread</tt> is in the ready state </li>
<li><b>symbol <tt>running</tt></b>: the <tt>thread</tt> is in the running state </li>
<li><b>symbol <tt>blocked</tt></b>: the <tt>thread</tt> is in the blocked state </li>
<li><b>symbol <tt>suspended</tt></b>: the <tt>thread</tt> is in the suspended state </li>
<li><b>symbol <tt>sleeping</tt></b>: the <tt>thread</tt> is in the sleeping state </li>
<li><b>symbol <tt>terminated</tt></b>: the <tt>thread</tt> is in the terminated state </li>
<li><b>symbol <tt>dead</tt></b>: the <tt>thread</tt> is in the dead state </li>
</ul>
</dd>
</dl>
<h2 id="sec:SRFI-18_specification"><a href="#sec:SRFI-18_specification">SRFI-18 specification</a></h2><p>The thread system provides the following data types:</p><ul><li>Thread (a virtual processor which shares object space with all other threads) </li>
<li>Mutex (a mutual exclusion device, also known as a lock and binary semaphore) </li>
<li>Condition variable (a set of blocked threads) </li>
<li>Time (an absolute point on the time line) </li>
</ul>
<p>Some multithreading exception datatypes are also specified, and a general mechanism for handling exceptions.</p><h3 id="sec:Background_information"><a href="#sec:Background_information">Background information</a></h3><h4 id="sec:Threads"><a href="#sec:Threads">Threads</a></h4><p>A "running" thread is a thread that is currently executing. There can be more than one running thread on a multiprocessor machine. A "runnable" thread is a thread that is ready to execute or running. A thread is "blocked" if it is waiting for a mutex to become unlocked, an I/O operation to become possible, the end of a "sleep" period, etc. A "new" thread is a thread that has not yet become runnable. A new thread becomes runnable when it is started. A "terminated" thread is a thread that can no longer become runnable (but "deadlocked" threads are not considered terminated). The only valid transitions between the thread states are from new to runnable, between runnable and blocked, and from any state to terminated:</p><pre> unblock
start <-------
NEW -------> RUNNABLE -------> BLOCKED
\ | block /
\ v /
+-----> TERMINATED <----+</pre><p>Each thread has a "specific" field which can be used in an application specific way to associate data with the thread (some thread systems call this "thread local storage").</p><h4 id="sec:Mutexes"><a href="#sec:Mutexes">Mutexes</a></h4><p>A mutex can be in one of four states: locked (either owned or not owned) and unlocked (either abandoned or not abandoned). An attempt to lock a mutex only succeeds if the mutex is in an unlocked state, otherwise the current thread must wait. A mutex in the locked/owned state has an associated "owner" thread, which by convention is the thread that is responsible for unlocking the mutex (this case is typical of critical sections implemented as "lock mutex, perform operation, unlock mutex"). A mutex in the locked/not-owned state is not linked to a particular thread. A mutex becomes locked when a thread locks it using the <tt>mutex-lock!</tt> primitive. A mutex becomes unlocked/abandoned when the owner of a locked/owned mutex terminates. A mutex becomes unlocked/not-abandoned when a thread unlocks it using the <tt>mutex-unlock!</tt> primitive. The mutex primitives specified in this SRFI do not implement "recursive" mutex semantics; an attempt to lock a mutex that is locked implies that the current thread must wait even if the mutex is owned by the current thread (this can lead to a deadlock if no other thread unlocks the mutex).</p><p>Each mutex has a "specific" field which can be used in an application specific way to associate data with the mutex.</p><h4 id="sec:Condition_variables"><a href="#sec:Condition_variables">Condition variables</a></h4><p>A condition variable represents a set of blocked threads. These blocked threads are waiting for a certain condition to become true. When a thread modifies some program state that might make the condition true, the thread unblocks some number of threads (one or all depending on the primitive used) so they can check the value of the condition. This allows complex forms of interthread synchronization to be expressed more conveniently than with mutexes alone.</p><p>Each condition variable has a "specific" field which can be used in an application specific way to associate data with the condition variable.</p><h4 id="sec:Fairness"><a href="#sec:Fairness">Fairness</a></h4><p>In various situations the scheduler must select one thread from a set of threads (e.g. which thread to run when a running thread blocks or expires its quantum, which thread to unblock when a mutex unlocks or a condition variable is signaled). The constraints on the selection process determine the scheduler's "fairness". Typically the selection depends on the order in which threads become runnable or blocked and on some "priority" attached to the threads.</p><p>Because we do not wish to preclude extensions to this SRFI (such as for real-time multithreading) that require specific fairness constraints, there are no fairness constraints imposed by this SRFI. It is expected however that implementations of Scheme that support this SRFI will document the fairness constraints they provide.</p><h4 id="sec:Memory_coherency_and_lack_of_atomicity"><a href="#sec:Memory_coherency_and_lack_of_atomicity">Memory coherency and lack of atomicity</a></h4><p>Read and write operations on the store (such as reading and writing a variable, an element of a vector or a string) are not required to be atomic. It is an error for a thread to write a location in the store while some other thread reads or writes that same location. It is the responsibility of the application to avoid write/read and write/write races through appropriate uses of the synchronization primitives.</p><p>Concurrent reads and writes to ports are allowed. It is the responsibility of the implementation to serialize accesses to a given port using the appropriate synchronization primitives.</p><h4 id="sec:Dynamic_environments.2c_continuations_and_dynamic-wind"><a href="#sec:Dynamic_environments.2c_continuations_and_dynamic-wind">Dynamic environments, continuations and <tt>dynamic-wind</tt></a></h4><p>The "dynamic environment" is a structure which allows the system to find the value returned by <tt>current-input-port</tt>, <tt>current-output-port</tt>, etc. The procedures <tt>with-input-from-file</tt>, <tt>with-output-to-file</tt>, etc extend the dynamic environment to produce a new dynamic environment which is in effect for the duration of the call to the thunk passed as the last argument. Some Scheme systems generalize the dynamic environment by providing procedures and special forms to define new "dynamic variables" and bind them in the dynamic environment (e.g. <tt>make-parameter</tt> and <tt>parameterize</tt>).</p><p>Each thread has its own dynamic environment. When a thread's dynamic environment is extended this does not affect the dynamic environment of other threads. When a thread creates a continuation, the thread's dynamic environment and the <tt>dynamic-wind</tt> stack are saved within the continuation (an alternate but equivalent point of view is that the <tt>dynamic-wind</tt> stack is part of the dynamic environment). When this continuation is invoked the required <tt>dynamic-wind</tt> before and after thunks are called and the saved dynamic environment is reinstated as the dynamic environment of the current thread. During the call to each required <tt>dynamic-wind</tt> before and after thunk, the dynamic environment and the <tt>dynamic-wind</tt> stack in effect when the corresponding <tt>dynamic-wind</tt> was executed are reinstated. Note that this specification clearly defines the semantics of calling <tt>call-with-current-continuation</tt> or invoking a continuation within a before or after thunk. The semantics are well defined even when a continuation created by another thread is invoked. Below is an example exercising the subtleties of this semantics.</p><pre> (with-output-to-file
"foo"
(lambda ()
(let ((k (call-with-current-continuation
(lambda (exit)
(with-output-to-file
"bar"
(lambda ()
(dynamic-wind
(lambda () (write '(b1)))
(lambda ()
(let ((x (call-with-current-continuation
(lambda (cont) (exit cont)))))
(write '(t1))
x))
(lambda () (write '(a1))))))))))
(if k
(dynamic-wind
(lambda () (write '(b2)))
(lambda ()
(with-output-to-file
"baz"
(lambda ()
(write '(t2))
; go back inside (with-output-to-file "bar" ...)
(k #f))))
(lambda () (write '(a2))))))))</pre><p>In an implementation of Scheme where <tt>with-output-to-file</tt> only closes the port it opened when the thunk returns normally, then the following actions will occur: <tt>(b1)(a1)</tt> is written to "bar", <tt>(b2)</tt> is written to "foo", <tt>(t2)</tt> is written to "baz", <tt>(a2)</tt> is written to "foo", and <tt>(b1)(t1)(a1)</tt> is written to "bar".</p><p>When the scheduler stops the execution of a running thread T1 (whether because it blocked, expired its quantum, was terminated, etc) and then resumes the execution of a thread T2, there is in a sense a transfer of control between T1's current continuation and the continuation of T2. This transfer of control by the scheduler does not cause any <tt>dynamic-wind</tt> before and after thunks to be called. It is only when a thread itself transfers control to a continuation that <tt>dynamic-wind</tt> before and after thunks are called.</p><h4 id="sec:Time_objects_and_timeouts"><a href="#sec:Time_objects_and_timeouts">Time objects and timeouts</a></h4><p>A time object represents a point on the time line. Its resolution is implementation dependent (implementations are encouraged to implement at least millisecond resolution so that precise timing is possible). Using <tt>time->seconds</tt> and <tt>seconds->time</tt>, a time object can be converted to and from a real number which corresponds to the number of seconds from a reference point on the time line. The reference point is implementation dependent and does not change for a given execution of the program (e.g. the reference point could be the time at which the program started).</p><p>All synchronization primitives which take a timeout parameter accept three types of values as a timeout, with the following meaning:</p><ul><li>a time object represents an absolute point in time </li>
<li>an exact or inexact real number represents a relative time in seconds from the moment the primitive was called </li>
<li><tt>#f</tt> means that there is no timeout </li>
</ul>
<p>When a timeout denotes the current time or a time in the past, the synchronization primitive claims that the timeout has been reached only after the other synchronization conditions have been checked. Moreover the thread remains running (it does not enter the blocked state). For example, <tt>(mutex-lock! m 0)</tt> will lock mutex <tt>m</tt> and return <tt>#t</tt> if <tt>m</tt> is currently unlocked, otherwise <tt>#f</tt> is returned because the timeout is reached.</p><h4 id="sec:Primitives_and_exceptions"><a href="#sec:Primitives_and_exceptions">Primitives and exceptions</a></h4><p>When one of the primitives defined in this SRFI raises an exception defined in this SRFI, the exception handler is called with the same continuation as the primitive (i.e. it is a tail call to the exception handler). This requirement avoids having to use <tt>call-with-current-continuation</tt> to get the same effect in some situations.</p><h4 id="sec:Primordial_thread"><a href="#sec:Primordial_thread">Primordial thread</a></h4><p>The execution of a program is initially under the control of a single thread known as the "primordial thread". The primordial thread has an unspecified name, specific field, dynamic environment, <tt>dynamic-wind</tt> stack, and exception handler. All threads are terminated when the primordial thread terminates (normally or not).</p><h3 id="sec:Procedures"><a href="#sec:Procedures">Procedures</a></h3><dl class="defsig"><dt class="defsig" id="def:current-thread"><span class="sig"><tt>(current-thread)</tt></span> <span class="type">procedure</span></dt>
<dd class="defsig"><p>Returns the current thread.</p><pre> (eq? (current-thread) (current-thread)) ==> #t</pre></dd>
</dl>
<dl class="defsig"><dt class="defsig" id="def:thread.3f"><span class="sig"><tt>(thread? obj)</tt></span> <span class="type">procedure</span></dt>
<dd class="defsig"><p>Returns <tt>#t</tt> if <tt>obj</tt> is a thread, otherwise returns <tt>#f</tt>.</p><pre> (thread? (current-thread)) ==> #t
(thread? 'foo) ==> #f</pre></dd>
</dl>
<dl class="defsig"><dt class="defsig" id="def:make-thread"><span class="sig"><tt>(make-thread thunk [name])</tt></span> <span class="type">procedure</span></dt>
<dd class="defsig"><p>Returns a new thread. This thread is not automatically made runnable (the procedure <tt>thread-start!</tt> must be used for this).</p><p>A thread has the following fields: name, specific, end-result, end-exception, and a list of locked/owned mutexes it owns. The thread's execution consists of a call to <i>thunk</i> with the "initial continuation". This continuation causes the (then) current thread to store the result in its end-result field, abandon all mutexes it owns, and finally terminate. The <tt>dynamic-wind</tt> stack of the initial continuation is empty. The optional <tt>name</tt> is an arbitrary Scheme object which identifies the thread (useful for debugging); it defaults to an unspecified value. The specific field is set to an unspecified value.</p><p>The thread inherits the dynamic environment from the current thread. Moreover, in this dynamic environment the exception handler is bound to the "initial exception handler" which is a unary procedure which causes the (then) current thread to store in its end-exception field an "uncaught exception" object whose "reason" is the argument of the handler, abandon all mutexes it owns, and finally terminate.</p><pre> (make-thread (lambda () (write 'hello))) ==> ''a thread''</pre></dd>
</dl>
<dl class="defsig"><dt class="defsig" id="def:thread-name"><span class="sig"><tt>(thread-name thread)</tt></span> <span class="type">procedure</span></dt>
<dd class="defsig"><p>Returns the name of the <tt>thread</tt>.</p><pre> (thread-name (make-thread (lambda () #f) 'foo)) ==> foo</pre></dd>
</dl>
<dl class="defsig"><dt class="defsig" id="def:thread-specific"><span class="sig"><tt>(thread-specific thread)</tt></span> <span class="type">procedure</span></dt>
<dd class="defsig"><p>Returns the content of the <tt>thread</tt>'s specific field.</p></dd>
</dl>
<dl class="defsig"><dt class="defsig" id="def:thread-specific-set.21"><span class="sig"><tt>(thread-specific-set! thread obj)</tt></span> <span class="type">procedure</span></dt>
<dd class="defsig"><p>Stores <tt>obj</tt> into the <tt>thread</tt>'s specific field. <tt>thread-specific-set!</tt> returns an unspecified value.</p><pre> (thread-specific-set! (current-thread) "hello") ==> ''unspecified''
(thread-specific (current-thread)) ==> "hello"</pre><p>Alternatively, you can use</p><pre> (set! (thread-specific (current-thread)) "hello")</pre></dd>
</dl>
<dl class="defsig"><dt class="defsig" id="def:thread-start.21"><span class="sig"><tt>(thread-start! thread)</tt></span> <span class="type">procedure</span></dt>
<dd class="defsig"><p>Makes <tt>thread</tt> runnable. The <tt>thread</tt> must be a new thread. <tt>thread-start!</tt> returns the <tt>thread</tt>.</p><pre> (let ((t (thread-start! (make-thread (lambda () (write 'a))))))
(write 'b)
(thread-join! t)) ==> ''unspecified''
''after writing'' ab ''or'' ba</pre><p>NOTE: It is useful to separate thread creation and thread activation to avoid the race condition that would occur if the created thread tries to examine a table in which the current thread stores the created thread. See the last example of <tt>thread-terminate!</tt> which contains mutually recursive threads.</p></dd>
</dl>
<dl class="defsig"><dt class="defsig" id="def:thread-yield.21"><span class="sig"><tt>(thread-yield!)</tt></span> <span class="type">procedure</span></dt>
<dd class="defsig"><p>The current thread exits the running state as if its quantum had expired. <tt>thread-yield!</tt> returns an unspecified value.</p><pre> ; a busy loop that avoids being too wasteful of the CPU
(let loop ()
(if (mutex-lock! m 0) ; try to lock m but don't block
(begin
(display "locked mutex m")
(mutex-unlock! m))
(begin
(do-something-else)
(thread-yield!) ; relinquish rest of quantum
(loop))))</pre></dd>
</dl>
<dl class="defsig"><dt class="defsig" id="def:thread-sleep.21"><span class="sig"><tt>(thread-sleep! timeout)</tt></span> <span class="type">procedure</span></dt>
<dd class="defsig"><p>The current thread waits until the timeout is reached. This blocks the thread only if <tt>timeout</tt> represents a point in the future. It is an error for <tt>timeout</tt> to be <tt>#f</tt>. <tt>thread-sleep!</tt> returns an unspecified value.</p><pre> ; a clock with a gradual drift:
(let loop ((x 1))
(thread-sleep! 1)
(write x)
(loop (+ x 1)))
; a clock with no drift:
(let ((start (time->seconds (current-time)))
(let loop ((x 1))
(thread-sleep! (seconds->time (+ x start)))
(write x)
(loop (+ x 1))))</pre></dd>
</dl>
<dl class="defsig"><dt class="defsig" id="def:thread-terminate.21"><span class="sig"><tt>(thread-terminate! thread)</tt></span> <span class="type">procedure</span></dt>
<dd class="defsig"><p>Causes an abnormal termination of the <tt>thread</tt>. If the <tt>thread</tt> is not already terminated, all mutexes owned by the <tt>thread</tt> become unlocked/abandoned and a "terminated thread exception" object is stored in the <tt>thread</tt>'s end-exception field. If <tt>thread</tt> is the current thread, <tt>thread-terminate!</tt> does not return. Otherwise <tt>thread-terminate!</tt> returns an unspecified value; the termination of the <tt>thread</tt> will occur before <tt>thread-terminate!</tt> returns.</p><pre> (thread-terminate! (current-thread)) ==> ''does not return''
(define (amb thunk1 thunk2)
(let ((result #f)
(result-mutex (make-mutex))
(done-mutex (make-mutex)))
(letrec ((child1
(make-thread
(lambda ()
(let ((x (thunk1)))
(mutex-lock! result-mutex #f #f)
(set! result x)
(thread-terminate! child2)
(mutex-unlock! done-mutex)))))
(child2
(make-thread
(lambda ()
(let ((x (thunk2)))
(mutex-lock! result-mutex #f #f)
(set! result x)
(thread-terminate! child1)
(mutex-unlock! done-mutex))))))
(mutex-lock! done-mutex #f #f)
(thread-start! child1)
(thread-start! child2)
(mutex-lock! done-mutex #f #f)
result)))</pre><p>NOTE: This operation must be used carefully because it terminates a thread abruptly and it is impossible for that thread to perform any kind of cleanup. This may be a problem if the thread is in the middle of a critical section where some structure has been put in an inconsistent state. However, another thread attempting to enter this critical section will raise an "abandoned mutex exception" because the mutex is unlocked/abandoned. This helps avoid observing an inconsistent state. Clean termination can be obtained by polling, as shown in the example below.</p><pre> (define (spawn thunk)
(let ((t (make-thread thunk)))
(thread-specific-set! t #t)
(thread-start! t)
t))
(define (stop! thread)
(thread-specific-set! thread #f)
(thread-join! thread))
(define (keep-going?)
(thread-specific (current-thread)))
(define count!
(let ((m (make-mutex))
(i 0))
(lambda ()
(mutex-lock! m)
(let ((x (+ i 1)))
(set! i x)
(mutex-unlock! m)
x))))
(define (increment-forever!)
(let loop () (count!) (if (keep-going?) (loop))))
(let ((t1 (spawn increment-forever!))
(t2 (spawn increment-forever!)))
(thread-sleep! 1)
(stop! t1)
(stop! t2)
(count!)) ==> 377290</pre></dd>
</dl>
<dl class="defsig"><dt class="defsig" id="def:thread-join.21"><span class="sig"><tt>(thread-join! thread [timeout [timeout-val]])</tt></span> <span class="type">procedure</span></dt>
<dd class="defsig"><p>The current thread waits until the <tt>thread</tt> terminates (normally or not) or until the timeout is reached if <tt>timeout</tt> is supplied. If the timeout is reached, <tt>thread-join!</tt> returns <tt>timeout-val</tt> if it is supplied, otherwise a "join timeout exception" is raised. If the <tt>thread</tt> terminated normally, the content of the end-result field is returned, otherwise the content of the end-exception field is raised.</p><pre> (let ((t (thread-start! (make-thread (lambda () (expt 2 100))))))
(do-something-else)
(thread-join! t)) ==> 1267650600228229401496703205376
(let ((t (thread-start! (make-thread (lambda () (raise 123))))))
(do-something-else)
(with-exception-handler
(lambda (exc)
(if (uncaught-exception? exc)
(* 10 (uncaught-exception-reason exc))
99999))
(lambda ()
(+ 1 (thread-join! t))))) ==> 1231
(define thread-alive?
(let ((unique (list 'unique)))
(lambda (thread)
; Note: this procedure raises an exception if
; the thread terminated abnormally.
(eq? (thread-join! thread 0 unique) unique))))
(define (wait-for-termination! thread)
(let ((eh (current-exception-handler)))
(with-exception-handler
(lambda (exc)
(if (not (or (terminated-thread-exception? exc)
(uncaught-exception? exc)))
(eh exc))) ; unexpected exceptions are handled by eh
(lambda ()
; The following call to thread-join! will wait until the
; thread terminates. If the thread terminated normally
; thread-join! will return normally. If the thread
; terminated abnormally then one of these two exceptions
; is raised by thread-join!:
; - terminated thread exception
; - uncaught exception
(thread-join! thread)
#f)))) ; ignore result of thread-join!</pre></dd>
</dl>
<dl class="defsig"><dt class="defsig" id="def:mutex.3f"><span class="sig"><tt>(mutex? obj)</tt></span> <span class="type">procedure</span></dt>
<dd class="defsig"><p>Returns <tt>#t</tt> if <tt>obj</tt> is a mutex, otherwise returns <tt>#f</tt>.</p><pre> (mutex? (make-mutex)) ==> #t
(mutex? 'foo) ==> #f</pre></dd>
</dl>
<dl class="defsig"><dt class="defsig" id="def:make-mutex"><span class="sig"><tt>(make-mutex [name])</tt></span> <span class="type">procedure</span></dt>
<dd class="defsig"><p>Returns a new mutex in the unlocked/not-abandoned state. The optional <tt>name</tt> is an arbitrary Scheme object which identifies the mutex (useful for debugging); it defaults to an unspecified value. The mutex's specific field is set to an unspecified value.</p><pre> (make-mutex) ==> ''an unlocked/not-abandoned mutex''
(make-mutex 'foo) ==> ''an unlocked/not-abandoned mutex named'' foo</pre></dd>
</dl>
<dl class="defsig"><dt class="defsig" id="def:mutex-name"><span class="sig"><tt>(mutex-name mutex)</tt></span> <span class="type">procedure</span></dt>
<dd class="defsig"><p>Returns the name of the <tt>mutex</tt>.</p><pre> (mutex-name (make-mutex 'foo)) ==> foo</pre></dd>
</dl>
<dl class="defsig"><dt class="defsig" id="def:mutex-specific"><span class="sig"><tt>(mutex-specific mutex)</tt></span> <span class="type">procedure</span></dt>
<dd class="defsig"><p>Returns the content of the <tt>mutex</tt>'s specific field.</p></dd>
</dl>
<dl class="defsig"><dt class="defsig" id="def:mutex-specific-set.21"><span class="sig"><tt>(mutex-specific-set! mutex obj)</tt></span> <span class="type">procedure</span></dt>
<dd class="defsig"><p>Stores <tt>obj</tt> into the <tt>mutex</tt>'s specific field. <tt>mutex-specific-set!</tt> returns an unspecified value.</p><pre> (define m (make-mutex))
(mutex-specific-set! m "hello") ==> ''unspecified''
(mutex-specific m) ==> "hello"
(define (mutex-lock-recursively! mutex)
(if (eq? (mutex-state mutex) (current-thread))
(let ((n (mutex-specific mutex)))
(mutex-specific-set! mutex (+ n 1)))
(begin
(mutex-lock! mutex)
(mutex-specific-set! mutex 0))))
(define (mutex-unlock-recursively! mutex)
(let ((n (mutex-specific mutex)))
(if (= n 0)
(mutex-unlock! mutex)
(mutex-specific-set! mutex (- n 1)))))</pre></dd>
</dl>
<dl class="defsig"><dt class="defsig" id="def:mutex-state"><span class="sig"><tt>(mutex-state mutex)</tt></span> <span class="type">procedure</span></dt>
<dd class="defsig"><p>Returns information about the state of the <tt>mutex</tt>. The possible results are:</p><ul><li><b>thread T</b>: the <tt>mutex</tt> is in the locked/owned state and thread T is the owner of the <tt>mutex</tt> </li>
<li><b>symbol <tt>not-owned</tt></b>: the <tt>mutex</tt> is in the locked/not-owned state </li>
<li><b>symbol <tt>abandoned</tt></b>: the <tt>mutex</tt> is in the unlocked/abandoned state </li>
<li><b>symbol <tt>not-abandoned</tt></b>: the <tt>mutex</tt> is in the unlocked/not-abandoned state </li>
</ul>
<pre> (mutex-state (make-mutex)) ==> not-abandoned
(define (thread-alive? thread)
(let ((mutex (make-mutex)))
(mutex-lock! mutex #f thread)
(let ((state (mutex-state mutex)))
(mutex-unlock! mutex) ; avoid space leak
(eq? state thread))))</pre></dd>
</dl>
<dl class="defsig"><dt class="defsig" id="def:mutex-lock.21"><span class="sig"><tt>(mutex-lock! mutex [timeout [thread]])</tt></span> <span class="type">procedure</span></dt>
<dd class="defsig"><p>If the <tt>mutex</tt> is currently locked, the current thread waits until the <tt>mutex</tt> is unlocked, or until the timeout is reached if <tt>timeout</tt> is supplied. If the timeout is reached, <tt>mutex-lock!</tt> returns <tt>#f</tt>. Otherwise, the state of the <tt>mutex</tt> is changed as follows:</p><ul><li>if <tt>thread</tt> is <tt>#f</tt> the <tt>mutex</tt> becomes locked/not-owned, </li>
<li>otherwise, let T be <tt>thread</tt> (or the current thread if <tt>thread</tt> is not supplied), <ul><li>if T is terminated the <tt>mutex</tt> becomes unlocked/abandoned, </li>
<li>otherwise <tt>mutex</tt> becomes locked/owned with T as the owner. </li>
</ul>
</li>
</ul>
<p>After changing the state of the <tt>mutex</tt>, an "abandoned mutex exception" is raised if the <tt>mutex</tt> was unlocked/abandoned before the state change, otherwise <tt>mutex-lock!</tt> returns <tt>#t</tt>. It is not an error if the <tt>mutex</tt> is owned by the current thread (but the current thread will have to wait).</p><pre> ; an implementation of a mailbox object of depth one; this
; implementation does not behave well in the presence of forced
; thread terminations using thread-terminate! (deadlock can occur
; if a thread is terminated in the middle of a put! or get! operation)
(define (make-empty-mailbox)
(let ((put-mutex (make-mutex)) ; allow put! operation
(get-mutex (make-mutex))
(cell #f))
(define (put! obj)
(mutex-lock! put-mutex #f #f) ; prevent put! operation
(set! cell obj)
(mutex-unlock! get-mutex)) ; allow get! operation
(define (get!)
(mutex-lock! get-mutex #f #f) ; wait until object in mailbox
(let ((result cell))
(set! cell #f) ; prevent space leaks
(mutex-unlock! put-mutex) ; allow put! operation
result))
(mutex-lock! get-mutex #f #f) ; prevent get! operation
(lambda (msg)
(case msg
((put!) put!)
((get!) get!)
(else (error "unknown message"))))))
(define (mailbox-put! m obj) ((m 'put!) obj))
(define (mailbox-get! m) ((m 'get!)))
; an alternate implementation of thread-sleep!
(define (sleep! timeout)
(let ((m (make-mutex)))
(mutex-lock! m #f #f)
(mutex-lock! m timeout #f)))
; a procedure that waits for one of two mutexes to unlock
(define (lock-one-of! mutex1 mutex2)
; this procedure assumes that neither mutex1 or mutex2
; are owned by the current thread
(let ((ct (current-thread))
(done-mutex (make-mutex)))
(mutex-lock! done-mutex #f #f)
(let ((t1 (thread-start!
(make-thread
(lambda ()
(mutex-lock! mutex1 #f ct)
(mutex-unlock! done-mutex)))))
(t2 (thread-start!
(make-thread
(lambda ()
(mutex-lock! mutex2 #f ct)
(mutex-unlock! done-mutex))))))
(mutex-lock! done-mutex #f #f)
(thread-terminate! t1)
(thread-terminate! t2)
(if (eq? (mutex-state mutex1) ct)
(begin
(if (eq? (mutex-state mutex2) ct)
(mutex-unlock! mutex2)) ; don't lock both
mutex1)
mutex2))))</pre></dd>
</dl>
<dl class="defsig"><dt class="defsig" id="def:mutex-unlock.21"><span class="sig"><tt>(mutex-unlock! mutex [condition-variable [timeout]])</tt></span> <span class="type">procedure</span></dt>
<dd class="defsig"><p>Unlocks the <tt>mutex</tt> by making it unlocked/not-abandoned. It is not an error to unlock an unlocked mutex and a mutex that is owned by any thread. If <tt>condition-variable</tt> is supplied, the current thread is blocked and added to the <tt>condition-variable</tt> before unlocking <tt>mutex</tt>; the thread can unblock at any time but no later than when an appropriate call to <tt>condition-variable-signal!</tt> or <tt>condition-variable-broadcast!</tt> is performed (see below), and no later than the timeout (if <tt>timeout</tt> is supplied). If there are threads waiting to lock this <tt>mutex</tt>, the scheduler selects a thread, the mutex becomes locked/owned or locked/not-owned, and the thread is unblocked. <tt>mutex-unlock!</tt> returns <tt>#f</tt> when the timeout is reached, otherwise it returns <tt>#t</tt>.</p><p>NOTE: The reason the thread can unblock at any time (when <tt>condition-variable</tt> is supplied) is to allow extending this SRFI with primitives that force a specific blocked thread to become runnable. For example a primitive to interrupt a thread so that it performs a certain operation, whether the thread is blocked or not, may be useful to handle the case where the scheduler has detected a serious problem (such as a deadlock) and it must unblock one of the threads (such as the primordial thread) so that it can perform some appropriate action. After a thread blocked on a condition-variable has handled such an interrupt it would be wrong for the scheduler to return the thread to the blocked state, because any calls to <tt>condition-variable-broadcast!</tt> during the interrupt will have gone unnoticed. It is necessary for the thread to remain runnable and return from the call to <tt>mutex-unlock!</tt> with a result of <tt>#t</tt>.</p><p>NOTE: <tt>mutex-unlock!</tt> is related to the "wait" operation on condition variables available in other thread systems. The main difference is that "wait" automatically locks <tt>mutex</tt> just after the thread is unblocked. This operation is not performed by <tt>mutex-unlock!</tt> and so must be done by an explicit call to <tt>mutex-lock!</tt>. This has the advantages that a different timeout and exception handler can be specified on the <tt>mutex-lock!</tt> and <tt>mutex-unlock!</tt> and the location of all the mutex operations is clearly apparent. A typical use with a condition variable is:</p><pre> (let loop ()
(mutex-lock! m)
(if (condition-is-true?)
(begin
(do-something-when-condition-is-true)
(mutex-unlock! m))
(begin
(mutex-unlock! m cv)
(loop))))</pre></dd>
</dl>
<dl class="defsig"><dt class="defsig" id="def:condition-variable.3f"><span class="sig"><tt>(condition-variable? obj)</tt></span> <span class="type">procedure</span></dt>
<dd class="defsig"><p>Returns <tt>#t</tt> if <tt>obj</tt> is a condition variable, otherwise returns <tt>#f</tt>.</p><pre> (condition-variable? (make-condition-variable)) ==> #t
(condition-variable? 'foo) ==> #f</pre></dd>
</dl>
<dl class="defsig"><dt class="defsig" id="def:make-condition-variable"><span class="sig"><tt>(make-condition-variable [name])</tt></span> <span class="type">procedure</span></dt>
<dd class="defsig"><p>Returns a new empty condition variable. The optional <tt>name</tt> is an arbitrary Scheme object which identifies the condition variable (useful for debugging); it defaults to an unspecified value. The condition variable's specific field is set to an unspecified value.</p><pre> (make-condition-variable) ==> ''an empty condition variable''</pre></dd>
</dl>
<dl class="defsig"><dt class="defsig" id="def:condition-variable-name"><span class="sig"><tt>(condition-variable-name condition-variable)</tt></span> <span class="type">procedure</span></dt>
<dd class="defsig"><p>Returns the name of the <tt>condition-variable</tt>.</p><pre> (condition-variable-name (make-condition-variable 'foo)) ==> foo</pre></dd>
</dl>
<dl class="defsig"><dt class="defsig" id="def:condition-variable-specific"><span class="sig"><tt>(condition-variable-specific condition-variable)</tt></span> <span class="type">procedure</span></dt>
<dd class="defsig"><p>Returns the content of the <tt>condition-variable</tt>'s specific field.</p></dd>
</dl>
<dl class="defsig"><dt class="defsig" id="def:condition-variable-specific-set.21"><span class="sig"><tt>(condition-variable-specific-set! condition-variable obj)</tt></span> <span class="type">procedure</span></dt>
<dd class="defsig"><p>Stores <tt>obj</tt> into the <tt>condition-variable</tt>'s specific field. <tt>condition-variable-specific-set!</tt> returns an unspecified value.</p><pre> (define cv (make-condition-variable))
(condition-variable-specific-set! cv "hello") ==> ''unspecified''
(condition-variable-specific cv) ==> "hello"</pre></dd>
</dl>
<dl class="defsig"><dt class="defsig" id="def:condition-variable-signal.21"><span class="sig"><tt>(condition-variable-signal! condition-variable)</tt></span> <span class="type">procedure</span></dt>
<dd class="defsig"><p>If there are threads blocked on the <tt>condition-variable</tt>, the scheduler selects a thread and unblocks it. <tt>condition-variable-signal!</tt> returns an unspecified value.</p><pre> ; an implementation of a mailbox object of depth one; this
; implementation behaves gracefully when threads are forcibly
; terminated using thread-terminate! (the "abandoned mutex"
; exception will be raised when a put! or get! operation is attempted
; after a thread is terminated in the middle of a put! or get!
; operation)
(define (make-empty-mailbox)
(let ((mutex (make-mutex))
(put-condvar (make-condition-variable))
(get-condvar (make-condition-variable))
(full? #f)
(cell #f))
(define (put! obj)
(mutex-lock! mutex)
(if full?
(begin
(mutex-unlock! mutex put-condvar)
(put! obj))
(begin
(set! cell obj)
(set! full? #t)
(condition-variable-signal! get-condvar)
(mutex-unlock! mutex))))
(define (get!)
(mutex-lock! mutex)
(if (not full?)
(begin
(mutex-unlock! mutex get-condvar)
(get!))
(let ((result cell))
(set! cell #f) ; avoid space leaks
(set! full? #f)
(condition-variable-signal! put-condvar)
(mutex-unlock! mutex))))
(lambda (msg)
(case msg
((put!) put!)
((get!) get!)
(else (error "unknown message"))))))
(define (mailbox-put! m obj) ((m 'put!) obj))
(define (mailbox-get! m) ((m 'get!)))</pre></dd>
</dl>
<dl class="defsig"><dt class="defsig" id="def:condition-variable-broadcast.21"><span class="sig"><tt>(condition-variable-broadcast! condition-variable)</tt></span> <span class="type">procedure</span></dt>
<dd class="defsig"><p>Unblocks all the threads blocked on the <tt>condition-variable</tt>. <tt>condition-variable-broadcast!</tt> returns an unspecified value.</p><pre> (define (make-semaphore n)
(vector n (make-mutex) (make-condition-variable)))
(define (semaphore-wait! sema)
(mutex-lock! (vector-ref sema 1))
(let ((n (vector-ref sema 0)))
(if (> n 0)
(begin
(vector-set! sema 0 (- n 1))
(mutex-unlock! (vector-ref sema 1)))
(begin
(mutex-unlock! (vector-ref sema 1) (vector-ref sema 2))
(semaphore-wait! sema))))
(define (semaphore-signal-by! sema increment)
(mutex-lock! (vector-ref sema 1))
(let ((n (+ (vector-ref sema 0) increment)))
(vector-set! sema 0 n)
(if (> n 0)
(condition-variable-broadcast! (vector-ref sema 2)))
(mutex-unlock! (vector-ref sema 1))))</pre></dd>
</dl>
<dl class="defsig"><dt class="defsig" id="def:current-time"><span class="sig"><tt>(current-time)</tt></span> <span class="type">procedure</span></dt>
<dd class="defsig"><p>Returns the time object corresponding to the current time.</p><pre> (current-time) ==> ''a time object''</pre></dd>
</dl>
<dl class="defsig"><dt class="defsig" id="def:time.3f"><span class="sig"><tt>(time? obj)</tt></span> <span class="type">procedure</span></dt>
<dd class="defsig"><p>Returns <tt>#t</tt> if <tt>obj</tt> is a time object, otherwise returns <tt>#f</tt>.</p><pre> (time? (current-time)) ==> #t
(time? 123) ==> #f</pre></dd>
</dl>
<dl class="defsig"><dt class="defsig" id="def:time-.3eseconds"><span class="sig"><tt>(time->seconds time)</tt></span> <span class="type">procedure</span></dt>
<dd class="defsig"><p>Converts the time object <tt>time</tt> into an exact or inexact real number representing the number of seconds elapsed since some implementation dependent reference point.</p><pre> (time->seconds (current-time)) ==> 955039784.928075</pre></dd>
</dl>
<dl class="defsig"><dt class="defsig" id="def:seconds-.3etime"><span class="sig"><tt>(seconds->time x)</tt></span> <span class="type">procedure</span></dt>
<dd class="defsig"><p>Converts into a time object the exact or inexact real number <tt>x</tt> representing the number of seconds elapsed since some implementation dependent reference point.</p><pre> (seconds->time (+ 10 (time->seconds (current-time)))
==> ''a time object representing 10 seconds in the future''</pre></dd>
</dl>
<dl class="defsig"><dt class="defsig" id="def:current-exception-handler"><span class="sig"><tt>(current-exception-handler)</tt></span> <span class="type">procedure</span></dt>
<dd class="defsig"><p>Returns the current exception handler.</p><pre> (current-exception-handler) ==> ''a procedure''</pre></dd>
</dl>
<dl class="defsig"><dt class="defsig" id="def:with-exception-handler"><span class="sig"><tt>(with-exception-handler handler thunk)</tt></span> <span class="type">procedure</span></dt>
<dd class="defsig"><p>Returns the result(s) of calling <tt>thunk</tt> with no arguments. The <tt>handler</tt>, which must be a procedure, is installed as the current exception handler in the dynamic environment in effect during the call to <tt>thunk</tt>.</p><pre> (with-exception-handler
list
current-exception-handler) ==> ''the procedure'' list</pre></dd>
</dl>
<dl class="defsig"><dt class="defsig" id="def:raise"><span class="sig"><tt>(raise obj)</tt></span> <span class="type">procedure</span></dt>
<dd class="defsig"><p>Calls the current exception handler with <tt>obj</tt> as the single argument. <tt>obj</tt> may be any Scheme object.</p><pre> (define (f n)
(if (< n 0) (raise "negative arg") (sqrt n))))
(define (g)
(call-with-current-continuation
(lambda (return)
(with-exception-handler
(lambda (exc)
(return
(if (string? exc)
(string-append "error: " exc)
"unknown error")))
(lambda ()
(write (f 4.))
(write (f -1.))
(write (f 9.)))))))
(g) ==> ''writes'' 2. ''and returns'' "error: negative arg"</pre></dd>
</dl>
<dl class="defsig"><dt class="defsig" id="def:join-timeout-exception.3f"><span class="sig"><tt>(join-timeout-exception? obj)</tt></span> <span class="type">procedure</span></dt>
<dd class="defsig"><p>Returns <tt>#t</tt> if <tt>obj</tt> is a "join timeout exception" object, otherwise returns <tt>#f</tt>. A join timeout exception is raised when <tt>thread-join!</tt> is called, the timeout is reached and no <tt>timeout-val</tt> is supplied.</p></dd>
</dl>
<dl class="defsig"><dt class="defsig" id="def:abandoned-mutex-exception.3f"><span class="sig"><tt>(abandoned-mutex-exception? obj)</tt></span> <span class="type">procedure</span></dt>
<dd class="defsig"><p>Returns <tt>#t</tt> if <tt>obj</tt> is an "abandoned mutex exception" object, otherwise returns <tt>#f</tt>. An abandoned mutex exception is raised when the current thread locks a mutex that was owned by a thread which terminated (see <tt>mutex-lock!</tt>).</p></dd>
</dl>
<dl class="defsig"><dt class="defsig" id="def:terminated-thread-exception.3f"><span class="sig"><tt>(terminated-thread-exception? obj)</tt></span> <span class="type">procedure</span></dt>
<dd class="defsig"><p>Returns <tt>#t</tt> if <tt>obj</tt> is a "terminated thread exception" object, otherwise returns <tt>#f</tt>. A terminated thread exception is raised when <tt>thread-join!</tt> is called and the target thread has terminated as a result of a call to <tt>thread-terminate!</tt>.</p></dd>
</dl>
<dl class="defsig"><dt class="defsig" id="def:uncaught-exception.3f"><span class="sig"><tt>(uncaught-exception? obj)</tt></span> <span class="type">procedure</span></dt>
<dd class="defsig"><p>Returns <tt>#t</tt> if <tt>obj</tt> is an "uncaught exception" object, otherwise returns <tt>#f</tt>. An uncaught exception is raised when <tt>thread-join!</tt> is called and the target thread has terminated because it raised an exception that called the initial exception handler of that thread.</p></dd>
</dl>
<dl class="defsig"><dt class="defsig" id="def:uncaught-exception-reason"><span class="sig"><tt>(uncaught-exception-reason exc)</tt></span> <span class="type">procedure</span></dt>
<dd class="defsig"><p><tt>exc</tt> must be an "uncaught exception" object. <tt>uncaught-exception-reason</tt> returns the object which was passed to the initial exception handler of that thread.</p></dd>
</dl>
<hr /><p>Previous: <a href="Unit%20srfi-14.html">Unit srfi-14</a></p><p>Next: <a href="Unit%20srfi-69.html">Unit srfi-69</a></p></div></div></body>
|