# 10.1 Multiple Values
(parameter)	→```
Returns #t if v has the [prop:exn:missing-module](#%28def._%28%28quote._~23~25kernel%29._prop~3aexn~3amissing-module%29%29) property, #f otherwise.
> ```
(exn:missing-module-accessor v)
  →  (exn:missing-module? .  →  . module-path?)
  v : exn:srclocs?
```
Returns the module path-getting procedure associated with v.

#### 10.2.6 Additional Exception Functions

|  |  |
|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------:|
|  (require racket/exn) |  package: base |

The bindings documented in this section are provided by the racket/exn library, not racket/base or racket.

Added in version 6.3 of package base.

> ```
(exn → string exn) → string?
  exn : (or/c exn? any/c)```

Formats exn as a string. If exn is an [exn?](#%28def._%28%28quote._~23~25kernel%29._exn~3f%29%29), collects and returns the output from the current ([error-display-handler](#%28def._%28%28quote._~23~25kernel%29._error-display-handler%29%29)); otherwise, simply converts exn to a string using ([format](Writing.html#%28def._%28%28quote._~23~25kernel%29._format%29%29) "\~s\\n" exn).

#### 10.2.7 Realms and Error Message Adjusters

A realm identifies a convention for naming functions and specifying contracts for function arguments and results. Realms are intended to help improve layering and interoperability among languages that are implemented on top of Racket.

Realms primarily enable a language to recognize and rewrite error messages that are generated by lower layers of an implementation. For example, a language’s implementation of “arrays” might use Racket vectors directly, but when an object-type or primitive bounds check fails for a vector, the generated error message mentions “vector” and possibly a contract like [vector?](vectors.html#%28def._%28%28quote._~23~25kernel%29._vector~3f%29%29) and a function name like [vector-ref](vectors.html#%28def._%28%28quote._~23~25kernel%29._vector-ref%29%29). Since these error messages are identified as being from the 'racket/primitive realm, a language implementation can look for 'racket/primitive to detect and rewrite error messages with minimal danger of mangling error messages from other parts of an application (possibly implemented in the new language) that happen to use the word “vector.”

Each procedure and each module also has a realm. A procedure’s realm is relevant, for example, when it is applied to the wrong number of arguments; in that case, the arity-error message itself is from the 'racket/primitive realm, but the error message also should include the name of the procedure, which can be from some different realm. Along similar lines, [continuation-mark-set->context](contmarks.html#%28def._%28%28quote._~23~25kernel%29._continuation-mark-set-~3econtext%29%29) can report the realm associated with (the procedure for) each frame in a continuation, which might be useful to identify boundary crossings.

The construction of an error message must cooperate explicitly with error-message adjusting. The most basic may to cooperate is through functions like [error-message->adjusted-string](#%28def._%28%28quote._~23~25kernel%29._error-message-~3eadjusted-string%29%29) and [error-contract->adjusted-string](#%28def._%28%28quote._~23~25kernel%29._error-contract-~3eadjusted-string%29%29), which run error-message adjusters via the [current-error-message-adjuster](#%28def._%28%28quote._~23~25kernel%29._current-error-message-adjuster%29%29) parameter and other adjusters associated with the current continuation using [error-message-adjuster-key](#%28def._%28%28quote._~23~25kernel%29._error-message-adjuster-key%29%29) as a [continuation-mark](eval-model.html#%28tech._continuation._mark%29) key. Functions like [raise-argument-error](#%28def._%28%28quote._~23~25kernel%29._raise-argument-error%29%29) and [raise-arity-error](#%28def._%28%28quote._~23~25kernel%29._raise-arity-error%29%29) use [error-message->adjusted-string](#%28def._%28%28quote._~23~25kernel%29._error-message-~3eadjusted-string%29%29) and [error-contract->adjusted-string](#%28def._%28%28quote._~23~25kernel%29._error-contract-~3eadjusted-string%29%29) with the default realm, 'racket. Functions like [raise-argument-error*](#%28def._%28%28quote._~23~25kernel%29._raise-argument-error%2A%29%29) and [raise-arity-error*](#%28def._%28%28quote._~23~25kernel%29._raise-arity-error%2A%29%29) accept an explicit realm argument.

Not all error functions automatically cooperate with error-message adjusting. For example, the raise-reader-error and [raise-syntax-error](#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._raise-syntax-error%29%29) functions do not call adjusters, because they report errors that are intimately tied to syntax (and, along those lines, errors of a more static nature).

> ```
(parameter)	→
(-> or/c symbol? #f)
```


# 10.1 Multiple Values
(parameter)	→```
Analogous to [error-message->adjusted-string](#%28def._%28%28quote._~23~25kernel%29._error-message-~3eadjusted-string%29%29), but for just the contract part of an error message. The result string is typically incorporated into a larger error message that may then be adjusted further.
Adjustment of contract string uses the 'contract protocol as described for [current-error-message-adjuster](#%28def._%28%28quote._~23~25kernel%29._current-error-message-adjuster%29%29).
Added in version 8.4.0.2 of package base.
> ```
(current-error-message-adjuster)	→
(-> symbol? . → . (or/c procedure? #f))
(current-error-message-adjuster proc) → void?
    proc	:
(-> symbol? . → . (or/c procedure? #f))


# 10.1 Multiple Values
```
(parameter)	→
(-> require [racket/promise]())```

Returns #t if v is a promise, #f otherwise.

>
<colgroup><col style="width: 100%" /></colgroup>

syntax

([delay](#%28form._%28%28lib._racket%2Fpromise..rkt%29._delay%29%29) body ...+)

Creates a promise that, when [force](#%28def._%28%28lib._racket%2Fpromise..rkt%29._force%29%29)d, evaluates the bodys to produce its value. The result is then cached, so further uses of [force](#%28def._%28%28lib._racket%2Fpromise..rkt%29._force%29%29) produce the cached value immediately. This includes multiple values and exceptions.

>
<colgroup><col style="width: 100%" /></colgroup>

syntax

([lazy](#%28form._%28%28lib._racket%2Fpromise..rkt%29._lazy%29%29) body ...+)

Like [delay](#%28form._%28%28lib._racket%2Fpromise..rkt%29._delay%29%29), if the last body produces a promise when forced, then this promise is [force](#%28def._%28%28lib._racket%2Fpromise..rkt%29._force%29%29)d, too, to obtain a value. In other words, this form creates a composable promise, where the computation of its body is “attached” to the computation of the following promise, and a single [force](#%28def._%28%28lib._racket%2Fpromise..rkt%29._force%29%29) iterates through the whole chain, tail-calling each step.

Note that the last body of this form must produce a single value, but the value can itself be a [delay](#%28form._%28%28lib._racket%2Fpromise..rkt%29._delay%29%29) promise that returns multiple values.

The [lazy](#%28form._%28%28lib._racket%2Fpromise..rkt%29._lazy%29%29) form is useful for implementing lazy libraries and languages, where tail calls can be wrapped in a promise.

> ```
(force v)  →  any
  v : any/c
```


# 10.1 Multiple Values
If v is a promise, then the promise is forced to obtain a value. If the promise has not been forced before, then the result is recorded in the promise so that future forces on the promise produce the same value (or values). If forcing the promise raises an exception, then the exception is similarly recorded so that forcing the promise will raise the same exception every time.
If v is forced again before the original call to force returns, then the exn:fail exception is raised.
If v is not a promise, then it is returned as the result.
> ```
(promise-forced? promise)   →   boolean?
  promise : promise?```
Returns #t if promise has been forced.
> ```
(promise-running? promise)  →  boolean?
  promise : promise?


# 10.1 Multiple Values
```
Returns #t if promise is currently being forced. (Note that a promise can be either running or forced but not both.)

#### 10.3.1 Additional Promise Kinds

> <table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><blockquote>

<p>syntax</p>

<p>(delay/name body ...+)</p></blockquote></td></tr></tbody></table>

Creates a “call-by-name” promise that is similar to delay-promises, except that the resulting value is not cached. This kind of promise is essentially a thunk that is wrapped in a way that force recognizes.

If a delay/name promise forces itself, no exception is raised, the promise is never considered “running” or “forced” in the sense of promise-running? and promise-forced?.

> ```
(promise/name? promise) → boolean?
  promise : any/c```

Returns #t if promise is a promise created with [delay/name](#%28form._%28%28lib._racket%2Fpromise..rkt%29._delay%2Fname%29%29).

Added in version 6.3 of package base.

> <table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><blockquote>

<p>syntax</p>

<p>([delay/strict](#%28form._%28%28lib._racket%2Fpromise..rkt%29._delay%2Fstrict%29%29) body ...+)</p></blockquote></td></tr></tbody></table>

Creates a “strict” promise: it is evaluated immediately, and the result is wrapped in a promise value. Note that the body can evaluate to multiple values, and forcing the resulting promise will return these values.

> <table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><blockquote>

<p>syntax</p>

<p>([delay/sync](#%28form._%28%28lib._racket%2Fpromise..rkt%29._delay%2Fsync%29%29) body ...+)</p></blockquote></td></tr></tbody></table>

Produces a promise where an attempt to [force](#%28def._%28%28lib._racket%2Fpromise..rkt%29._force%29%29) the promise by a thread other than one currently running the promise causes the [force](#%28def._%28%28lib._racket%2Fpromise..rkt%29._force%29%29) to block until a result is available. This kind of promise is also a [synchronizable event](sync.html#%28tech._synchronizable._event%29) for use with [sync](sync.html#%28def._%28%28quote._~23~25kernel%29._sync%29%29); [sync](sync.html#%28def._%28%28quote._~23~25kernel%29._sync%29%29)ing on the promise does not [force](#%28def._%28%28lib._racket%2Fpromise..rkt%29._force%29%29) it, but merely waits until a value is forced by another thread. The [synchronization result](sync.html#%28tech._synchronization._result%29) is [#<void>](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=guide&rel=void_undefined.html&version=8.18.0.13).

If a promise created by [delay/sync](#%28form._%28%28lib._racket%2Fpromise..rkt%29._delay%2Fsync%29%29) is forced on a thread that is already running the promise, an exception is raised in the same way as for promises created with [delay](#%28form._%28%28lib._racket%2Fpromise..rkt%29._delay%29%29).

> <table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><blockquote>

<p>syntax</p>

<p>([delay/thread](#%28form._%28%28lib._racket%2Fpromise..rkt%29._delay%2Fthread%29%29) body/option ...+)</p></blockquote></td></tr><tr><td> </td></tr><tr><td><table data-cellpadding="0" data-cellspacing="0"><tbody><tr><td style="text-align: right;" data-valign="baseline">body/option</td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: center;" data-valign="baseline">=</td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline">body</td></tr><tr><td style="text-align: right;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: center;" data-valign="baseline">|</td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline">#:group thread-group-expr</td></tr></tbody></table></td></tr></tbody></table>

Like [delay/sync](#%28form._%28%28lib._racket%2Fpromise..rkt%29._delay%2Fsync%29%29), but begins the computation immediately on a newly created thread. The thread is created under the [thread group](threadgroups.html#%28tech._thread._group%29) specified by thread-group-expr, which defaults to ([make-thread-group](threadgroups.html#%28def._%28%28quote._~23~25kernel%29._make-thread-group%29%29)). A #:group specification can appear at most once.

Exceptions raised by the bodys are caught as usual and raised only when the promise is [force](#%28def._%28%28lib._racket%2Fpromise..rkt%29._force%29%29)d. Unlike [delay/sync](#%28form._%28%28lib._racket%2Fpromise..rkt%29._delay%2Fsync%29%29), if the thread running body terminates without producing a result or exception, [force](#%28def._%28%28lib._racket%2Fpromise..rkt%29._force%29%29) of the promise raises an exception (instead of blocking).

> <table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><blockquote>

<p>syntax</p>

<p>([delay/idle](#%28form._%28%28lib._racket%2Fpromise..rkt%29._delay%2Fidle%29%29) body/option ...+)</p></blockquote></td></tr><tr><td> </td></tr><tr><td><table data-cellpadding="0" data-cellspacing="0"><tbody><tr><td style="text-align: right;" data-valign="baseline">body/option</td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: center;" data-valign="baseline">=</td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline">body</td></tr><tr><td style="text-align: right;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: center;" data-valign="baseline">|</td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline">#:wait-for wait-evt-expr</td></tr><tr><td style="text-align: right;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: center;" data-valign="baseline">|</td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline">#:work-while while-evt-expr</td></tr><tr><td style="text-align: right;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: center;" data-valign="baseline">|</td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline">#:tick tick-secs-expr</td></tr><tr><td style="text-align: right;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: center;" data-valign="baseline">|</td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline">#:use use-ratio-expr</td></tr></tbody></table></td></tr></tbody></table>

Like [delay/thread](#%28form._%28%28lib._racket%2Fpromise..rkt%29._delay%2Fthread%29%29), but with the following differences:

-   the computation does not start until the event produced by wait-evt-expr is ready, where the default is ([system-idle-evt](sync.html#%28def._%28%28quote._~23~25kernel%29._system-idle-evt%29%29));

-   the computation thread gets to work only when the process is otherwise idle as determined by while-evt-expr, which also defaults to ([system-idle-evt](sync.html#%28def._%28%28quote._~23~25kernel%29._system-idle-evt%29%29));

-   the thread is allowed to run only periodically: out of every tick-secs-expr (defaults to 0.2) seconds, the thread is allowed to run use-ratio-expr (defaults to 0.12) of the time proportionally; i.e., the thread runs for ([*](generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._%2A%29%29) tick-secs-expr use-ratio-expr) seconds.

If the promise is forced before the computation is done, it runs the rest of the computation immediately without waiting on events or periodically restricting evaluation.

A #:wait-for, #:work-while, #:tick, or #:use specification can appear at most once.

> ```
syntax

(for/list/concurrent maybe-group (for-clause ...)
> body-or-break ... body )

maybe-group   =
    |   #:group thread-group-expr

   thread-group-expr   :   thread-group?
```


# 10.1 Multiple Values
Iterates like for/list, but the bodies (following any #:break or #:final clauses) are wrapped in delay/thread. Each promise is forced before the result list is returned.
Threads are created under thread-group-expr, which defaults to (make-thread-group). An optional #:group clause may be provided, in which case the threads will be created under that thread group.
This form does not support returning multiple values.
Example:
> ```racket
> > ( time ( for/list/concurrent ( [ i ( in-range 5 ) ] ) ( define duration ( / 1.0 ( random 50 100 ) ) ) ( sleep duration ) ( printf "thread ~a slept for ~a milliseconds~n" i ( truncate ( * duration 1000 ) ) ) i ) )
> thread 4 slept for 11.0 milliseconds thread 0 slept for 11.0 milliseconds thread 1 slept for 14.0 milliseconds thread 3 slept for 16.0 milliseconds thread 2 slept for 17.0 milliseconds cpu time: 97 real time: 18 gc time: 9
> '(0 1 2 3 4)
> ```
Added in version 8.6.0.4 of package base.
> ```
syntax
(for*/list/concurrent maybe-group (for-clause ...)
> body-or-break ... body )```
Like [for/list/concurrent](#%28form._%28%28lib._racket%2Fpromise..rkt%29._for%2Flist%2Fconcurrent%29%29), but with the implicit nesting of [for*/list](for.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._for%2A%2Flist%29%29).
Added in version 8.6.0.4 of package base.
------------------------------------------------------------------------


# 10.4 Continuations


### 10.4 Continuations
> > > <img src="finger.png" width="24" height="24" alt="+" />[Continuations](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=guide&rel=conts.html&version=8.18.0.13) in [The Racket Guide](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=guide&rel=index.html&version=8.18.0.13) introduces continuations.
See [Sub-expression Evaluation and Continuations](eval-model.html#%28part._cont-model%29) and [Prompts, Delimited Continuations, and Barriers](eval-model.html#%28part._prompt-model%29) for general information about continuations. Racket’s support for prompts and composable continuations \[[Flatt07](doc-bibliography.html#%28cite._.Flatt07%29)\] closely resembles Sitaram’s % and fcontrol operator \[[Sitaram93](doc-bibliography.html#%28cite._.Sitaram93%29)\].
Racket installs a [continuation barrier](eval-model.html#%28tech._continuation._barrier%29) around evaluation in the following contexts, preventing full-continuation jumps into the evaluation context protected by the barrier:
-   applying an exception handler, an error escape handler, or an error display handler (see [Exceptions](exns.html));
-   applying a macro transformer (see [Syntax Transformers](stxtrans.html)), evaluating a compile-time expression, or applying a module name resolver (see [Resolving Module Names](Module_Names_and_Loading.html#%28part._modnameresolver%29));


# 10.4 Continuations
-   applying a custom-port procedure (see [Custom Ports](customport.html)), an event guard procedure (see [Events](sync.html)), or a parameter guard procedure (see [Parameters](parameters.html));
-   applying a security-guard procedure (see [Security Guards](securityguards.html));
-   applying a will procedure (see [Wills and Executors](willexecutor.html)); or
-   evaluating or loading code from the stand-alone Racket command line (see [Running Racket or GRacket](running-sa.html)).
In addition, extensions of Racket may install barriers in additional contexts. Finally, [call-with-continuation-barrier](#%28def._%28%28quote._~23~25kernel%29._call-with-continuation-barrier%29%29) applies a thunk barrier between the application and the current continuation.
> ```
(call-with-continuation-prompt proc
   [ prompt-tag
    handler]
    arg ...)    →    any
  proc : procedure?
   prompt-tag   :   continuation-prompt-tag?
      =   (default-continuation-prompt-tag)
  handler : (or/c procedure? #f) = #f
  arg : any/c


# 10.4 Continuations
```
(parameter)	→```

Resets the current continuation to that of the nearest prompt tagged by prompt-tag in the current continuation; if no such prompt exists, the [exn:fail:contract:continuation](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3afail~3acontract~3acontinuation%29%29) exception is raised. The vs are delivered as arguments to the target prompt’s handler procedure.

The protocol for vs supplied to an abort is specific to the prompt-tag. When [abort-current-continuation](#%28def._%28%28quote._~23~25kernel%29._abort-current-continuation%29%29) is used with ([default-continuation-prompt-tag](#%28def._%28%28quote._~23~25kernel%29._default-continuation-prompt-tag%29%29)), generally, a single thunk should be supplied that is suitable for use with the default prompt handler. Similarly, when [call-with-continuation-prompt](#%28def._%28%28quote._~23~25kernel%29._call-with-continuation-prompt%29%29) is used with ([default-continuation-prompt-tag](#%28def._%28%28quote._~23~25kernel%29._default-continuation-prompt-tag%29%29)), the associated handler should generally accept a single thunk argument.

Each [thread](eval-model.html#%28tech._thread%29)’s continuation starts with a prompt for ([default-continuation-prompt-tag](#%28def._%28%28quote._~23~25kernel%29._default-continuation-prompt-tag%29%29)) that uses the default handler, which accepts a single thunk to apply (with the prompt intact).

> ```
(make-continuation-prompt-tag)	→
(-> make-continuation-prompt-tag name)
(make-continuation-prompt-tag name) → continuation-prompt-tag?
    name	:
(-> make-continuation-prompt-tag name)
```


# 10.4 Continuations
Creates a prompt tag that is not equal? to the result of any other value (including prior or future results from make-continuation-prompt-tag). The optional name argument, if supplied, specifies the name of the prompt tag for printing or object-name.
Changed in version 7.9.0.13 of package base: The name argument gives the name of the prompt tag.
> ```
(default-continuation-prompt-tag)   →   continuation-prompt-tag?```
Returns a constant prompt tag for which a prompt is installed at the start of every thread’s continuation; the handler for each thread’s initial prompt accepts any number of values and returns. The result of [default-continuation-prompt-tag](#%28def._%28%28quote._~23~25kernel%29._default-continuation-prompt-tag%29%29) is the default tag for any procedure that accepts a prompt tag.
> ```
(default-continuation-prompt-tag)	→
(-> continuation? . → . any)
```
(default-continuation-prompt-tag)	→
(-> continuation? . → . any)```

The [call/cc](#%28def._%28%28lib._racket%2Fprivate%2Fmore-scheme..rkt%29._call%2Fcc%29%29) binding is an alias for [call-with-current-continuation](#%28def._%28%28quote._~23~25kernel%29._call-with-current-continuation%29%29).

> ```
(call-with-composable-continuation proc
   [ prompt-tag)    →    any

  proc : (continuation? .  →  . any)
   prompt-tag   :   continuation-prompt-tag?
      =   (default-continuation-prompt-tag)
```
(parameter)	→
(-> continuation? . → . any)```


# 10.4 Continuations
Like [call-with-current-continuation](#%28def._%28%28quote._~23~25kernel%29._call-with-current-continuation%29%29), but proc is not called in tail position, and the continuation procedure supplied to proc can only be called during the dynamic extent of the [call-with-escape-continuation](#%28def._%28%28quote._~23~25kernel%29._call-with-escape-continuation%29%29) call.
A continuation obtained from [call-with-escape-continuation](#%28def._%28%28quote._~23~25kernel%29._call-with-escape-continuation%29%29) is actually a kind of prompt. Escape continuations are provided mainly for backwards compatibility, since they pre-date general prompts in Racket. In the [BC](implementations.html#%28tech._bc%29) implementation of Racket, [call-with-escape-continuation](#%28def._%28%28quote._~23~25kernel%29._call-with-escape-continuation%29%29) is implemented more efficiently than [call-with-current-continuation](#%28def._%28%28quote._~23~25kernel%29._call-with-current-continuation%29%29), so [call-with-escape-continuation](#%28def._%28%28quote._~23~25kernel%29._call-with-escape-continuation%29%29) can sometimes replace [call-with-current-continuation](#%28def._%28%28quote._~23~25kernel%29._call-with-current-continuation%29%29) to improve performance in those older Racket variants.
> ```
(call/ec proc)  →  any
  proc : (continuation? .  →  . any)


# 10.4 Continuations
```
The call/ec binding is an alias for call-with-escape-continuation.

> ```
(call-in-continuation k proc)   →   any
  k : continuation?
  proc : (  →   any)```

Similar to applying the continuation k, but instead of delivering values to the continuation, proc is called with k as the continuation of the call (so the result of proc is returned to the continuation). If k is a composable continuation, the continuation of the call to proc is the current continuation extended with k.

Examples:

> ```racket
> > ( + 1 ( call/cc ( lambda ( k ) ( call-in-continuation k ( lambda ( ) 4 ) ) ) ) )
> 5
> > ( + 1 ( call/cc ( lambda ( k ) ( let ( [ n 0 ] ) ( dynamic-wind void ( lambda ( ) ; n accessed after post thunk ( call-in-continuation k ( lambda ( ) n ) ) ) ( lambda ( ) ( set! n 4 ) ) ) ) ) ) )
> 5
> > ( + 1 ( with-continuation-mark ' n 4 ( call/cc ( lambda ( k ) ( with-continuation-mark ' n 0 ( call-in-continuation k ( lambda ( ) ; ' n mark accessed in continuation ( continuation-mark-set-first #f ' n ) ) ) ) ) ) ) )
> 5
> ```

Added in version 7.6.0.17 of package base.

> <table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><blockquote>

<p>syntax</p>

<p>([let/cc](#%28form._%28%28lib._racket%2Fprivate%2Fmore-scheme..rkt%29._let%2Fcc%29%29) k body ...+)</p></blockquote></td></tr></tbody></table>

Equivalent to ([call/cc](#%28def._%28%28lib._racket%2Fprivate%2Fmore-scheme..rkt%29._call%2Fcc%29%29) ([lambda](lambda.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._lambda%29%29) (k) body [...](stx-patterns.html#%28form._%28%28lib._racket%2Fprivate%2Fstxcase-scheme..rkt%29._......%29%29))).

> <table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><blockquote>

<p>syntax</p>

<p>([let/ec](#%28form._%28%28lib._racket%2Fprivate%2Fletstx-scheme..rkt%29._let%2Fec%29%29) k body ...+)</p></blockquote></td></tr></tbody></table>

Equivalent to ([call/ec](#%28def._%28%28lib._racket%2Fprivate%2Fletstx-scheme..rkt%29._call%2Fec%29%29) ([lambda](lambda.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._lambda%29%29) (k) body [...](stx-patterns.html#%28form._%28%28lib._racket%2Fprivate%2Fstxcase-scheme..rkt%29._......%29%29))).

> ```
(call-with-continuation-barrier thunk)  →  any
  thunk : (  →   any)
```


# 10.4 Continuations
Applies thunk with a continuation barrier between the application and the current continuation. The results of thunk are the results of the call-with-continuation-barrier call.
> ```
(continuation-prompt-available? prompt-tag
   [ cont)    →    any
  prompt-tag : continuation-prompt-tag?
  cont : continuation? = (call/cc values)```
Returns #t if cont, which must be a continuation, includes a prompt tagged by prompt-tag, #f otherwise.
> ```
(continuation? v)  →  boolean?
  v : any/c
```
(parameter)	→```

Returns #t if v is a continuation prompt tag as produced by [default-continuation-prompt-tag](#%28def._%28%28quote._~23~25kernel%29._default-continuation-prompt-tag%29%29) or [make-continuation-prompt-tag](#%28def._%28%28quote._~23~25kernel%29._make-continuation-prompt-tag%29%29).

> ```
(dynamic-wind   pre-thunk
    value-thunk
    post-thunk)    →    any

  pre-thunk : (  →   any)
  value-thunk : (  →   any)
  post-thunk : (  →   any)
```
(default-continuation-prompt-tag)	→
(-> default-continuation-prompt-tag)```
The [call/prompt](#%28def._%28%28lib._racket%2Fcontrol..rkt%29._call%2Fprompt%29%29) binding is an alias for [call-with-continuation-prompt](#%28def._%28%28quote._~23~25kernel%29._call-with-continuation-prompt%29%29).
> ```
(abort/cc prompt-tag v ...) → any
  prompt-tag : any/c
  v : any/c


# 10.4 Continuations
```
(default-continuation-prompt-tag)	→
(-> continuation? . → . any)```

The [call/comp](#%28def._%28%28lib._racket%2Fcontrol..rkt%29._call%2Fcomp%29%29) binding is an alias for [call-with-composable-continuation](#%28def._%28%28quote._~23~25kernel%29._call-with-composable-continuation%29%29).

> ```
(abort v ...) → any
  v : any/c
```
(default-continuation-prompt-tag)	→
(-> default-continuation-prompt-tag)```
Sitaram’s operators \[[Sitaram93](doc-bibliography.html#%28cite._.Sitaram93%29)\].
The essential reduction rules are:
> ```racket
> ( % val proc ) => val
> ( % E [ ( fcontrol val ) ] proc ) => ( proc val ( lambda ( x ) E [ x ] ) )
> ; where E has no %
> ```
When handler-expr is omitted, [%](#%28form._%28%28lib._racket%2Fcontrol..rkt%29._~25%29%29) is the same as [prompt](#%28form._%28%28lib._racket%2Fcontrol..rkt%29._prompt%29%29). If prompt-tag is provided, [%](#%28form._%28%28lib._racket%2Fcontrol..rkt%29._~25%29%29) uses specific prompt tags like [prompt-at](#%28form._%28%28lib._racket%2Fcontrol..rkt%29._prompt-at%29%29).
Examples:
> ```racket
> > ( % ( + 2 ( fcontrol 5 ) ) ( lambda ( v k ) ( k v ) ) )
> 7
> > ( % ( + 2 ( fcontrol 5 ) ) ( lambda ( v k ) v ) )
> 5
> ```
>
<colgroup><col style="width: 100%" /></colgroup>

<colgroup><col style="width: 100%" /></colgroup>

syntax


# 10.4 Continuations

([prompt](#%28form._%28%28lib._racket%2Fcontrol..rkt%29._prompt%29%29) expr ...+)

<colgroup><col style="width: 100%" /></colgroup>

syntax

([control](#%28form._%28%28lib._racket%2Fcontrol..rkt%29._control%29%29) id expr ...+)

Among the earliest operators for higher-order control \[[Felleisen88a](doc-bibliography.html#%28cite._.Felleisen88a%29), [Felleisen88](doc-bibliography.html#%28cite._.Felleisen88%29), [Sitaram90](doc-bibliography.html#%28cite._.Sitaram90%29)\].
The essential reduction rules are:
> ```racket
> ( prompt val ) => val
> ( prompt E [ ( control k expr ) ] ) => ( prompt ( ( lambda ( k ) expr )
> ( lambda ( v ) E [ v ] ) ) )
> ; where E has no prompt
> ```
Examples:
> ```racket
> > ( prompt ( + 2 ( control k ( k 5 ) ) ) )
> 7
> > ( prompt ( + 2 ( control k 5 ) ) )
> 5
> > ( prompt ( + 2 ( control k ( + 1 ( control k1 ( k1 6 ) ) ) ) ) )
> 7
> > ( prompt ( + 2 ( control k ( + 1 ( control k1 ( k 6 ) ) ) ) ) )
> 8
> > ( prompt ( + 2 ( control k ( control k1 ( control k2 ( k2 6 ) ) ) ) ) )
> 6
> ```
>
<colgroup><col style="width: 100%" /></colgroup>

<colgroup><col style="width: 100%" /></colgroup>

syntax


# 10.4 Continuations

([prompt-at](#%28form._%28%28lib._racket%2Fcontrol..rkt%29._prompt-at%29%29) prompt-tag-expr expr ...+)

<colgroup><col style="width: 100%" /></colgroup>

syntax

([control-at](#%28form._%28%28lib._racket%2Fcontrol..rkt%29._control-at%29%29) prompt-tag-expr id expr ...+)

Like [prompt](#%28form._%28%28lib._racket%2Fcontrol..rkt%29._prompt%29%29) and [control](#%28form._%28%28lib._racket%2Fcontrol..rkt%29._control%29%29), but using specific prompt tags:
> ```racket
> ( prompt-at tag val ) => val
> ( prompt-at tag E [ ( control-at tag k expr ) ] ) => ( prompt-at tag
> ( ( lambda ( k ) expr )
> ( lambda ( v ) E [ v ] ) ) )
> ; where E has no prompt-at for tag
> ```
>
<colgroup><col style="width: 100%" /></colgroup>

<colgroup><col style="width: 100%" /></colgroup>

syntax

([reset](#%28form._%28%28lib._racket%2Fcontrol..rkt%29._reset%29%29) expr ...+)

<colgroup><col style="width: 100%" /></colgroup>

syntax

([shift](#%28form._%28%28lib._racket%2Fcontrol..rkt%29._shift%29%29) id expr ...+)


# 10.4 Continuations
Danvy and Filinski’s operators \[[Danvy90](doc-bibliography.html#%28cite._.Danvy90%29)\].
The essential reduction rules are:
> ```racket
> ( reset val ) => val
> ( reset E [ ( shift k expr ) ] ) => ( reset ( ( lambda ( k ) expr )
> ( lambda ( v ) ( reset E [ v ] ) ) ) )
> ; where E has no reset
> ```
The [reset](#%28form._%28%28lib._racket%2Fcontrol..rkt%29._reset%29%29) and [prompt](#%28form._%28%28lib._racket%2Fcontrol..rkt%29._prompt%29%29) forms are interchangeable.
>
<colgroup><col style="width: 100%" /></colgroup>

<colgroup><col style="width: 100%" /></colgroup>

syntax

([reset-at](#%28form._%28%28lib._racket%2Fcontrol..rkt%29._reset-at%29%29) prompt-tag-expr expr ...+)

<colgroup><col style="width: 100%" /></colgroup>

syntax

([shift-at](#%28form._%28%28lib._racket%2Fcontrol..rkt%29._shift-at%29%29) prompt-tag-expr identifier expr ...+)

Like [reset](#%28form._%28%28lib._racket%2Fcontrol..rkt%29._reset%29%29) and [shift](#%28form._%28%28lib._racket%2Fcontrol..rkt%29._shift%29%29), but using the specified prompt tags.


# 10.4 Continuations
>
<colgroup><col style="width: 100%" /></colgroup>

<colgroup><col style="width: 100%" /></colgroup>

syntax

([prompt0](#%28form._%28%28lib._racket%2Fcontrol..rkt%29._prompt0%29%29) expr ...+)

<colgroup><col style="width: 100%" /></colgroup>

syntax

([reset0](#%28form._%28%28lib._racket%2Fcontrol..rkt%29._reset0%29%29) expr ...+)

<colgroup><col style="width: 100%" /></colgroup>

syntax

([control0](#%28form._%28%28lib._racket%2Fcontrol..rkt%29._control0%29%29) id expr ...+)

<colgroup><col style="width: 100%" /></colgroup>

syntax

([shift0](#%28form._%28%28lib._racket%2Fcontrol..rkt%29._shift0%29%29) id expr ...+)

Generalizations of [prompt](#%28form._%28%28lib._racket%2Fcontrol..rkt%29._prompt%29%29), etc. \[[Shan04](doc-bibliography.html#%28cite._.Shan04%29)\].
The essential reduction rules are:


# 10.4 Continuations
> ```racket
> ( prompt0 val ) => val
> ( prompt0 E [ ( control0 k expr ) ] ) => ( ( lambda ( k ) expr )
> ( lambda ( v ) E [ v ] ) )
> ( reset0 val ) => val
> ( reset0 E [ ( shift0 k expr ) ] ) => ( ( lambda ( k ) expr )
> ( lambda ( v ) ( reset0 E [ v ] ) ) )
> ```
The [reset0](#%28form._%28%28lib._racket%2Fcontrol..rkt%29._reset0%29%29) and [prompt0](#%28form._%28%28lib._racket%2Fcontrol..rkt%29._prompt0%29%29) forms are interchangeable. Furthermore, the following reductions apply:
> ```racket
> ( prompt E [ ( control0 k expr ) ] ) => ( prompt ( ( lambda ( k ) expr )
> ( lambda ( v ) E [ v ] ) ) )
> ( reset E [ ( shift0 k expr ) ] ) => ( reset ( ( lambda ( k ) expr )
> ( lambda ( v ) ( reset0 E [ v ] ) ) ) )
> ( prompt0 E [ ( control k expr ) ] ) => ( prompt0 ( ( lambda ( k ) expr )
> ( lambda ( v ) E [ v ] ) ) )
> ( reset0 E [ ( shift k expr ) ] ) => ( reset0 ( ( lambda ( k ) expr )
> ( lambda ( v ) ( reset E [ v ] ) ) ) )
> ```
That is, both the [prompt](#%28form._%28%28lib._racket%2Fcontrol..rkt%29._prompt%29%29)/[reset](#%28form._%28%28lib._racket%2Fcontrol..rkt%29._reset%29%29) and [control](#%28form._%28%28lib._racket%2Fcontrol..rkt%29._control%29%29)/[shift](#%28form._%28%28lib._racket%2Fcontrol..rkt%29._shift%29%29) sites must agree for 0-like behavior, otherwise the non-0 behavior applies.
>
<colgroup><col style="width: 100%" /></colgroup>

<colgroup><col style="width: 100%" /></colgroup>

syntax


# 10.4 Continuations

([prompt0-at](#%28form._%28%28lib._racket%2Fcontrol..rkt%29._prompt0-at%29%29) prompt-tag-expr expr ...+)

<colgroup><col style="width: 100%" /></colgroup>

syntax

([reset0-at](#%28form._%28%28lib._racket%2Fcontrol..rkt%29._reset0-at%29%29) prompt-tag-expr expr ...+)

<colgroup><col style="width: 100%" /></colgroup>

syntax

([control0-at](#%28form._%28%28lib._racket%2Fcontrol..rkt%29._control0-at%29%29) prompt-tag-expr id expr ...+)

<colgroup><col style="width: 100%" /></colgroup>

syntax

([shift0-at](#%28form._%28%28lib._racket%2Fcontrol..rkt%29._shift0-at%29%29) prompt-tag-expr id expr ...+)

Variants of [prompt0](#%28form._%28%28lib._racket%2Fcontrol..rkt%29._prompt0%29%29), etc., that accept a prompt tag.
> ```
(spawn proc)  →  any
  proc : ((any/c .  →  . any) .  →  . any)


# 10.4 Continuations
```
The operators of Hieb and Dybvig \[Hieb90\].

The essential reduction rules are:

> ```racket
> ( spawn proc )
> => ( prompt/spawn tag
> ( proc ( lambda ( proc ) ( abort/spawn tag proc ) ) ) )
> ; where tag is a freshly generated prompt tag
> ( prompt/spawn tag val )
> => val
> ( prompt/spawn tag E [ ( abort/spawn tag proc ) ] )
> => ( proc ( lambda ( x ) ( prompt/spawn tag E [ x ] ) ) )
> ; where E has no prompt/spawn for tag
> ```

> ```
(splitter proc) → any
   proc   :   ( ( (  →  any ) .  →  . any )
> ( ( continuation? .  →  . any ) .  →  . any )
> .  →  . any )```

The operator of Queinnec and Serpette \[[Queinnec91](doc-bibliography.html#%28cite._.Queinnec91%29)\].

The essential reduction rules are:

> ```racket
> ( splitter proc )
> => ( prompt/splitter tag
> ( proc ( lambda ( thunk ) ( abort/splitter tag thunk ) )
> ( lambda ( proc ) ( control0/splitter tag k ( proc k ) ) ) ) )
> ; where tag is a freshly generated prompt tag
> ( prompt/splitter tag val )
> => val
> ( prompt/splitter tag E [ ( abort/splitter tag thunk ) ] )
> => ( thunk )
> ; where E has no prompt/splitter for tag
> ( prompt/splitter tag E [ ( control0/splitter tag k expr ) ] )
> => ( ( lambda ( k ) expr )
> ( lambda ( x ) E [ x ] ) )
> ; where E has no prompt/splitter for tag
> ```

> ```
(new-prompt)	→
(-> new-prompt name)
(new-prompt name) → continuation-prompt-tag?
    name	:
(-> new-prompt name)
```
(current-continuation-marks)	→
(-> or/c continuation? thread? #f)```


# 10.4 Continuations
Returns an opaque value containing the set of continuation marks for all keys in the continuation cont (or the current continuation of cont if it is a thread) up to the prompt tagged by prompt-tag. If cont is #f, the resulting set of continuation marks is empty. If cont is an escape continuation (see [Prompts, Delimited Continuations, and Barriers](eval-model.html#%28part._prompt-model%29)), then the current continuation must extend cont, or the [exn:fail:contract](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3afail~3acontract%29%29) exception is raised. If cont was not captured with respect to prompt-tag and does not include a prompt for prompt-tag, the [exn:fail:contract](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3afail~3acontract%29%29) exception is raised. If cont is a dead thread, the result is an empty set of continuation marks.
> ```
(default-continuation-prompt-tag)	→
(-> default-continuation-prompt-tag)


# 10.4 Continuations
```
(default-continuation-prompt-tag)	→
(-> or/c continuation-mark-set? #f)```

Returns a newly-created list containing the marks for key-v in mark-set, which is a set of marks returned by [current-continuation-marks](#%28def._%28%28quote._~23~25kernel%29._current-continuation-marks%29%29) or #f as a shorthand for ([current-continuation-marks](#%28def._%28%28quote._~23~25kernel%29._current-continuation-marks%29%29) prompt-tag). The result list is truncated at the first point, if any, where continuation frames were originally separated by a prompt tagged with prompt-tag. Producing the result takes time proportional to the size of the continuation reflected by mark-set.

Changed in version 8.0.0.1 of package base: Changed to allow mark-set as #f.

> ```
(continuation-mark-set → list* mark-set
    key-list
   [ none-v
    prompt-tag)    →    (listof vector?)

  mark-set : (or/c continuation-mark-set? #f)
  key-list : (listof any/c)
  none-v : any/c = #f
   prompt-tag   :   continuation-prompt-tag?
      =   (default-continuation-prompt-tag)
```
(default-continuation-prompt-tag)	→
(-> (values (or/c vector? #f) procedure?))```


# 10.4 Continuations
Like [continuation-mark-set->list*](#%28def._%28%28quote._~23~25kernel%29._continuation-mark-set-~3elist%2A%29%29), but instead of returning a list of values, returns a functional iterator in the form of a procedure that returns one element of the would-be list and a new iterator function for the rest of the would-be list. An iterator procedure returns #f instead of a vector when no more elements are available; in that case, the returned iterator procedure is like the called one, producing no further values. The time required for each step is proportional to the length of key-list times the size of the segment of the continuation reflected by mark-set between frames that have keys in key-list.
Added in version 7.5.0.7 of package base.
Changed in version 8.0.0.1: Changed to allow mark-set as #f.
> ```
(continuation-mark-set-first mark-set
    key-v
   [ none-v
    prompt-tag)    →    any
  mark-set : (or/c continuation-mark-set? #f)
  key-v : any/c
  none-v : any/c = #f
   prompt-tag   :   continuation-prompt-tag?
      =   (default-continuation-prompt-tag)


# 10.4 Continuations
```
(amortized)	→
(-> or mark-set (current-continuation-marks prompt-tag))```

Calls proc with the value associated with key-v in the first frame of the current continuation (i.e., a value that would be replaced if the call to [call-with-immediate-continuation-mark](#%28def._%28%28quote._~23~25kernel%29._call-with-immediate-continuation-mark%29%29) were replaced with a [with-continuation-mark](wcm.html#%28form._%28%28quote._~23~25kernel%29._with-continuation-mark%29%29) form using key-v as the key expression). If no such value exists in the first frame, default-v is passed to proc. The proc is called in tail position with respect to the [call-with-immediate-continuation-mark](#%28def._%28%28quote._~23~25kernel%29._call-with-immediate-continuation-mark%29%29) call.

This function could be implemented with a combination of [with-continuation-mark](wcm.html#%28form._%28%28quote._~23~25kernel%29._with-continuation-mark%29%29), [current-continuation-marks](#%28def._%28%28quote._~23~25kernel%29._current-continuation-marks%29%29), and [continuation-mark-set->list*](#%28def._%28%28quote._~23~25kernel%29._continuation-mark-set-~3elist%2A%29%29), as shown below, but [call-with-immediate-continuation-mark](#%28def._%28%28quote._~23~25kernel%29._call-with-immediate-continuation-mark%29%29) is implemented more efficiently; it inspects only the first frame of the current continuation.

> ```racket
> ; Equivalent, but inefficient:
> ( define ( call-with-immediate-continuation-mark key-v proc [ default-v #f ] )
> ( define private-key ( gensym ) )
> ( with-continuation-mark
> private-key #t
> ( let ( [ vecs ( continuation-mark-set->list* ( current-continuation-marks )
> ( list key-v private-key )
> default-v ) ] )
> ( proc ( vector-ref ( car vecs ) 0 ) ) ) ) )
> ```

> ```
(make-continuation-mark-key)	→
(-> make-continuation-mark-key sym)
(make-continuation-mark-key sym) → continuation-mark-key?
    sym	:
(-> make-continuation-mark-key sym)
```


# 10.4 Continuations
Creates a continuation mark key that is not equal? to the result of any other value (including prior and future results from make-continuation-mark-key). The continuation mark key can be used as the key argument for with-continuation-mark or accessor procedures like continuation-mark-set-first. The mark key can be chaperoned or impersonated, unlike other values that are used as the mark key.
The optional sym argument, if provided, is used when printing the continuation mark.
> ```
(continuation-mark-key? v)   →   boolean?
  v : any/c```
Returns #t if v is a mark key created by [make-continuation-mark-key](#%28def._%28%28quote._~23~25kernel%29._make-continuation-mark-key%29%29), #f otherwise.
> ```
(continuation-mark-set? v)  →  boolean?
  v : any/c


# 10.4 Continuations
```
(parameter)	→```

Returns a list representing an approximate “stack trace” for mark-set’s continuation. The list contains pairs if realms? is #f, where the [car](pairs.html#%28def._%28%28quote._~23~25kernel%29._car%29%29) of each pair contains either #f or a symbol for a procedure name, and the [cdr](pairs.html#%28def._%28%28quote._~23~25kernel%29._cdr%29%29) of each pair contains either #f or a [srcloc](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._srcloc%29%29) value for the procedure’s source location (see [Counting Positions, Lines, and Columns](linecol.html)); the [car](pairs.html#%28def._%28%28quote._~23~25kernel%29._car%29%29) and [cdr](pairs.html#%28def._%28%28quote._~23~25kernel%29._cdr%29%29) are never both #f. If realms? is true, the list contains 3-element vectors, where the first two elements are like the values for a pair, and the third element is a realm symbol.

Conceptually, the stack-trace list is the result of [continuation-mark-set->list](#%28def._%28%28quote._~23~25kernel%29._continuation-mark-set-~3elist%29%29) with mark-set and Racket’s private key for procedure-call marks. The implementation may be different, however, and the results may merely approximate the correct answer. Thus, while the result may contain useful hints to humans about the context of an expression, it is not reliable enough for programmatic use.

A stack trace is extracted from an exception and displayed by the default error display handler (see [error-display-handler](exns.html#%28def._%28%28quote._~23~25kernel%29._error-display-handler%29%29)) for exceptions other than [exn:fail:user](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3afail~3auser%29%29) (see [raise-user-error](exns.html#%28def._%28%28quote._~23~25kernel%29._raise-user-error%29%29) in [Raising Exceptions](exns.html#%28part._errorproc%29)).

Examples:

> ```racket
> > ( define ( extract-current-continuation-marks key ) ( continuation-mark-set->list ( current-continuation-marks ) key ) )
> > ( with-continuation-mark ' key ' mark ( extract-current-continuation-marks ' key ) )
> '(mark)
> > ( with-continuation-mark ' key1 ' mark1 ( with-continuation-mark ' key2 ' mark2 ( list ( extract-current-continuation-marks ' key1 ) ( extract-current-continuation-marks ' key2 ) ) ) )
> '((mark1) (mark2))
> > ( with-continuation-mark ' key ' mark1 ( with-continuation-mark ' key ' mark2 ; replaces previous mark ( extract-current-continuation-marks ' key ) ) )
> '(mark2)
> > ( with-continuation-mark ' key ' mark1 ( list ; continuation extended to evaluate the argument ( with-continuation-mark ' key ' mark2 ( extract-current-continuation-marks ' key ) ) ) )
> '((mark2 mark1))
> > ( let loop ( [ n 1000 ] ) ( if ( zero? n ) ( extract-current-continuation-marks ' key ) ( with-continuation-mark ' key n ( loop ( sub1 n ) ) ) ) )
> '(1)
> ```

Changed in version 8.4.0.2 of package base: Added the realms? argument.

------------------------------------------------------------------------

# 10.6 Breaks

### 10.6 Breaks

A break is an asynchronous exception, usually triggered through an external source controlled by the user, or through the [break-thread](threads.html#%28def._%28%28quote._~23~25kernel%29._break-thread%29%29) procedure. For example, the user may type Ctl-C in a terminal to trigger a break. On some platforms, the Racket process may receive SIGINT, SIGHUP, or SIGTERM; the latter two correspond to hang-up and terminate breaks as reflected by [exn:break:hang-up](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3abreak~3ahang-up%29%29) and [exn:break:terminate](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3abreak~3aterminate%29%29), respectively. Multiple breaks may be collapsed into a single exception, and multiple breaks of different kinds may be collapsed to a single “strongest” break, where a terminate break is stronger than a hang-up break which is stronger than an interrupt break.

A break exception can only occur in a thread while breaks are enabled. When a break is detected and enabled, the [exn:break](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3abreak%29%29) (or [exn:break:hang-up](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3abreak~3ahang-up%29%29) or [exn:break:terminate](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3abreak~3aterminate%29%29)) exception is raised in the thread sometime afterward; if breaking is disabled when [break-thread](threads.html#%28def._%28%28quote._~23~25kernel%29._break-thread%29%29) is called, the break is suspended until breaking is again enabled for the thread. While a thread has a suspended break, additional breaks are ignored.

Breaks are enabled through the [break-enabled](#%28def._%28%28quote._~23~25kernel%29._break-enabled%29%29) parameter-like procedure and through the [parameterize-break](#%28form._%28%28lib._racket%2Fprivate%2Fmore-scheme..rkt%29._parameterize-break%29%29) form, which is analogous to [parameterize](parameters.html#%28form._%28%28lib._racket%2Fprivate%2Fmore-scheme..rkt%29._parameterize%29%29). The [break-enabled](#%28def._%28%28quote._~23~25kernel%29._break-enabled%29%29) procedure does not represent a parameter to be used with [parameterize](parameters.html#%28form._%28%28lib._racket%2Fprivate%2Fmore-scheme..rkt%29._parameterize%29%29), because changing the break-enabled state of a thread requires an explicit check for breaks, and this check is incompatible with the tail evaluation of a [parameterize](parameters.html#%28form._%28%28lib._racket%2Fprivate%2Fmore-scheme..rkt%29._parameterize%29%29) expression’s body.

Certain procedures, such as [semaphore-wait/enable-break](semaphore.html#%28def._%28%28quote._~23~25kernel%29._semaphore-wait%2Fenable-break%29%29), enable breaks temporarily while performing a blocking action. If breaks are enabled for a thread, and if a break is triggered for the thread but not yet delivered as an [exn:break](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3abreak%29%29) exception, then the break is guaranteed to be delivered before breaks can be disabled in the thread. The timing of [exn:break](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3abreak%29%29) exceptions is not guaranteed in any other way.

Before calling a [with-handlers](exns.html#%28form._%28%28lib._racket%2Fprivate%2Fmore-scheme..rkt%29._with-handlers%29%29) predicate or handler, an exception handler, an error display handler, an error escape handler, an error value conversion handler, or a pre-thunk or post-thunk for a [dynamic-wind](cont.html#%28def._%28%28quote._~23~25kernel%29._dynamic-wind%29%29), the call is [parameterize-break](#%28form._%28%28lib._racket%2Fprivate%2Fmore-scheme..rkt%29._parameterize-break%29%29)ed to disable breaks. Furthermore, breaks are disabled during the transitions among handlers related to exceptions, during the transitions between pre-thunks and post-thunks for [dynamic-wind](cont.html#%28def._%28%28quote._~23~25kernel%29._dynamic-wind%29%29), and during other transitions for a continuation jump. For example, if breaks are disabled when a continuation is invoked, and if breaks are also disabled in the target continuation, then breaks will remain disabled from the time of the invocation until the target continuation executes unless a relevant [dynamic-wind](cont.html#%28def._%28%28quote._~23~25kernel%29._dynamic-wind%29%29) pre-thunk or post-thunk explicitly enables breaks.

If a break is triggered for a thread that is blocked on a nested thread (see [call-in-nested-thread](threads.html#%28def._%28%28quote._~23~25kernel%29._call-in-nested-thread%29%29)), and if breaks are enabled in the blocked thread, the break is implicitly handled by transferring it to the nested thread.

When breaks are enabled, they can occur at any point within execution, which makes certain implementation tasks subtle. For example, assuming breaks are enabled when the following code is executed,

> ```racket
> ( with-handlers ( [ exn:break? ( lambda ( x ) ( void ) ) ] )
> ( semaphore-wait s ) )
> ```

then it is not the case that a [#<void>](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=guide&rel=void_undefined.html&version=8.18.0.13) result means the semaphore was decremented or a break was received, exclusively. It is possible that both occur: the break may occur after the semaphore is successfully decremented but before a [#<void>](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=guide&rel=void_undefined.html&version=8.18.0.13) result is returned by [semaphore-wait](semaphore.html#%28def._%28%28quote._~23~25kernel%29._semaphore-wait%29%29). A break exception will never damage a semaphore, or any other built-in construct, but many built-in procedures (including [semaphore-wait](semaphore.html#%28def._%28%28quote._~23~25kernel%29._semaphore-wait%29%29)) contain internal sub-expressions that can be interrupted by a break.

In general, it is impossible using only [semaphore-wait](semaphore.html#%28def._%28%28quote._~23~25kernel%29._semaphore-wait%29%29) to implement the guarantee that either the semaphore is decremented or an exception is raised, but not both. Racket therefore supplies [semaphore-wait/enable-break](semaphore.html#%28def._%28%28quote._~23~25kernel%29._semaphore-wait%2Fenable-break%29%29) (see [Semaphores](semaphore.html)), which does permit the implementation of such an exclusive guarantee:

> ```racket
> ( parameterize-break #f
> ( with-handlers ( [ exn:break? ( lambda ( x ) ( void ) ) ] )
> ( semaphore-wait/enable-break s ) ) )
> ```

In the above expression, a break can occur at any point until breaks are disabled, in which case a break exception is propagated to the enclosing exception handler. Otherwise, the break can only occur within [semaphore-wait/enable-break](semaphore.html#%28def._%28%28quote._~23~25kernel%29._semaphore-wait%2Fenable-break%29%29), which guarantees that if a break exception is raised, the semaphore will not have been decremented.

To allow similar implementation patterns over blocking port operations, Racket provides [read-bytes-avail!/enable-break](Byte_and_String_Input.html#%28def._%28%28quote._~23~25kernel%29._read-bytes-avail%21%2Fenable-break%29%29), [write-bytes-avail/enable-break](Byte_and_String_Output.html#%28def._%28%28quote._~23~25kernel%29._write-bytes-avail%2Fenable-break%29%29), and other procedures.

> ```
(break-enabled)	→
(-> break-enabled on?)
```


# 10.4 Continuations
(current-break-parameterization)	→```
Analogous to ([current-parameterization](parameters.html#%28def._%28%28lib._racket%2Fprivate%2Fmore-scheme..rkt%29._current-parameterization%29%29)) (see [Parameters](parameters.html)); it returns a break parameterization (effectively, a thread cell) that holds the current continuation’s break-enable state.
> ```
(call-with-break-parameterization   break-param
    thunk)    →    any
  break-param : break-parameterization?
  thunk : (  →   any)
```
(parameter)	→```

Returns #t if v is a break parameterization as produced by [current-break-parameterization](#%28def._%28%28lib._racket%2Fprivate%2Fmore-scheme..rkt%29._current-break-parameterization%29%29), #f otherwise.

Added in version 6.1.1.8 of package base.

------------------------------------------------------------------------

# 10.7 Exiting

### 10.7 Exiting

> ```
(exit [v) → any
  v : any/c = #t
```
(exit-handler)	→
(-> any/c . → . any)
(exit-handler proc) → void?
    proc	:
(-> any/c . → . any)```
A [parameter](eval-model.html#%28tech._parameter%29) that determines the current exit handler. The [exit handler](#%28tech._exit._handler%29) is called by [exit](#%28def._%28%28quote._~23~25kernel%29._exit%29%29).


# 10.4 Continuations
The default [exit handler](#%28tech._exit._handler%29) in the Racket executable takes any argument, calls [plumber-flush-all](plumbers.html#%28def._%28%28quote._~23~25kernel%29._plumber-flush-all%29%29) on the original plumber, and shuts down the OS-level Racket process. The argument is used as the OS-level exit code if it is an exact integer between 1 and 255 (which normally means “failure”); otherwise, the exit code is 0, (which normally means “success”).
> ```
(executable-yield-handler)	→
(-> byte? . → . any)
(executable-yield-handler proc) → void?
    proc	:
(-> byte? . → . any)


# 10.4 Continuations
```
(assert-unreachable)	→```

Reports an assertion failure by raising [exn:fail:contract](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3afail~3acontract%29%29), which is useful as a safe counterpart to [unsafe-assert-unreachable](unsafe.html#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-assert-unreachable%29%29).

Added in version 8.0.0.11 of package base.

#### 10.8.1 Customized Unreachable Reporting

|                                                                                |                                                                                |
|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------:|
|  ([require](require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._require%29%29) [racket/unreachable](#%28mod-path._racket%2Funreachable%29)) |  package: [base](https://pkgs.racket-lang.org/package/base "Install this package using `raco pkg install base`") |

The bindings documented in this section are provided by the [racket/unreachable](#%28mod-path._racket%2Funreachable%29) library, not [racket/base](index.html) or [racket](index.html).

Added in version 8.0.0.11 of package base.

> ```
syntax

(with-assert-unreachable
> body ...+ )
```


# 10.4 Continuations
(assert-unreachable)	→
(-> any)```
Calls thunk with no arguments in a new thread of control. The [thread](#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._thread%29%29) procedure returns immediately with a thread descriptor value. When the invocation of thunk returns, the thread created to invoke thunk terminates.
The resulting thread is a [coroutine thread](eval-model.html#%28tech._coroutine._thread%29) if pool is #f. If pool is 'own, then a new [parallel thread pool](#%28tech._parallel._thread._pool%29) is created, the thread is added to the pool, and the pool is closed (in the sense of [parallel-thread-pool-close](#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._parallel-thread-pool-close%29%29)) to additional threads. If pool is a parallel thread pool, then the new thread is created in that pool, meaning that it shares processor resources with other threads in the same pool. See [Parallel Threads](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=guide&rel=parallelism.html%23%2528part._parallel-threads%2529&version=8.18.0.13) for information about parallel threads and performance. Parallel threads do not run in parallel on the [BC](implementations.html#%28tech._bc%29) variant of Racket or when Racket is built without support for parallelism. For more information, see the description of [parallel thread pools](#%28tech._parallel._thread._pool%29).


# 10.4 Continuations
If keep is 'results, results are recorded with the thread so that they can be reported by [thread-wait](#%28def._%28%28quote._~23~25kernel%29._thread-wait%29%29). Otherwise, then the results of thunk are ignored.
Changed in version 8.18.0.2 of package base: Added the #:pool and #:keep arguments.
> ```
(thread? v)  →  thread?
  v : any/c
```
(current-thread)	→```

Returns the [thread descriptor](#%28tech._thread._descriptor%29) for the currently executing thread.

> ```
(thread/suspend-to-kill thunk)  →  thread?
  thunk : (  →   any)
```
(current-custodian)	→
(-> any)```
Creates a nested thread managed by cust to execute thunk. (The nested thread’s current custodian is inherited from the creating thread, independent of the cust argument.) The current thread blocks until thunk returns, and the result of the [call-in-nested-thread](#%28def._%28%28quote._~23~25kernel%29._call-in-nested-thread%29%29) call is the result returned by thunk.
The nested thread’s exception handler is initialized to a procedure that jumps to the beginning of the thread and transfers the exception to the original thread. The handler thus terminates the nested thread and re-raises the exception in the original thread.


# 10.4 Continuations
If the thread created by [call-in-nested-thread](#%28def._%28%28quote._~23~25kernel%29._call-in-nested-thread%29%29) dies before thunk returns, the [exn:fail](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3afail%29%29) exception is raised in the original thread. If the original thread is killed before thunk returns, a break is queued for the nested thread.
If a break is queued for the original thread (with [break-thread](#%28def._%28%28quote._~23~25kernel%29._break-thread%29%29)) while the nested thread is running, the break is redirected to the nested thread. If a break is already queued on the original thread when the nested thread is created, the break is moved to the nested thread. If a break remains queued on the nested thread when it completes, the break is moved to the original thread.
If the thread created by [call-in-nested-thread](#%28def._%28%28quote._~23~25kernel%29._call-in-nested-thread%29%29) dies while itself in a call to [call-in-nested-thread](#%28def._%28%28quote._~23~25kernel%29._call-in-nested-thread%29%29), the outer call to [call-in-nested-thread](#%28def._%28%28quote._~23~25kernel%29._call-in-nested-thread%29%29) waits for the innermost nested thread to complete, and any breaks pending on the inner threads are moved to the original thread.


#### 11.1.2 Suspending, Resuming, and Killing Threads
> ```
(parameter)	→
```
(parameter)	→
(-> or/c thread? custodian? #f)```

Resumes the execution of thd if it is suspended and has at least one custodian (possibly added through benefactor, as described below). If the thread has terminated, or if the thread is already running and benefactor is not supplied, or if the thread has no custodian and benefactor is not supplied, then [thread-resume](#%28def._%28%28quote._~23~25kernel%29._thread-resume%29%29) has no effect. Otherwise, if benefactor is supplied, it triggers up to three additional actions:

-   If benefactor is a thread, whenever it is resumed from a suspended state in the future, then thd is also resumed. (Resuming thd may trigger the resumption of other threads that were previously attached to thd through [thread-resume](#%28def._%28%28quote._~23~25kernel%29._thread-resume%29%29).)

-   New custodians may be added to thd’s set of managers. If benefactor is a thread, then all of the thread’s custodians are added to thd. Otherwise, benefactor is a custodian, and it is added to thd (unless the custodian is already shut down). If thd becomes managed by both a custodian and one or more of its subordinates, the redundant subordinates are removed from thd. If thd is suspended and a custodian is added, then thd is resumed only after the addition.

-   If benefactor is a thread, whenever it receives a new managing custodian in the future, then thd also receives the custodian. (Adding custodians to thd may trigger adding the custodians to other threads that were previously attached to thd through [thread-resume](#%28def._%28%28quote._~23~25kernel%29._thread-resume%29%29).)

> ```
(parameter)	→
```


# 10.4 Continuations
(parameter)	→
(-> or/c #f 'hang-up 'terminate)```
Registers a break with the specified thread. The optional kind value indicates the kind of break to register, where #f, 'hang-up, and 'terminate correspond to interrupt, hang-up, and terminate breaks respectively. If breaking is disabled in thd, the break will be ignored until breaks are re-enabled. See [Breaks](breakhandler.html) for details.
> ```
(parameter)	→
(-> =/c 0)
```

Causes the current thread to sleep until at least secs seconds have passed after it starts sleeping. A zero value for secs simply acts as a hint to allow other threads to execute. The value of secs can be a non-integer to request a sleep duration to any precision; the precision of the actual sleep time is unspecified.

> ```
(thread-running? thd)  →  any
  thd : thread?
```
Returns #t if thd has not terminated and is not suspended, #f otherwise.
> ```
(thread-dead? thd)  →  any
  thd : thread?


# 10.4 Continuations
```
Returns #t if thd has terminated, #f otherwise.

#### 11.1.3 Synchronizing Thread State

> ```
(thread-wait thd [fail-k) → any
  thd : thread?
  fail-k : (procedure-arity-includes/c 0) = void```

Blocks execution of the current thread until thd has terminated. If the thread’s procedure raised an exception or otherwise aborted to the thread’s initial [prompt](eval-model.html#%28tech._prompt%29), fail-k is called to produce the result of [thread-wait](#%28def._%28%28quote._~23~25kernel%29._thread-wait%29%29). Otherwise, if the thread records its results (see #:keep in [thread](#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._thread%29%29)), those results are returned, while [#<void>](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=guide&rel=void_undefined.html&version=8.18.0.13) is return if the thread does not keep its results.

Note that ([thread-wait](#%28def._%28%28quote._~23~25kernel%29._thread-wait%29%29) ([current-thread](#%28def._%28%28quote._~23~25kernel%29._current-thread%29%29))) deadlocks the current thread, but a break can end the deadlock if breaking is enabled and if the thread is the main thread or otherwise accessible; see [Breaks](breakhandler.html).

Unless thd was created with [thread/suspend-to-kill](#%28def._%28%28quote._~23~25kernel%29._thread%2Fsuspend-to-kill%29%29), a ([thread-wait](#%28def._%28%28quote._~23~25kernel%29._thread-wait%29%29) thd) may potentially continue even if thd is otherwise inaccessible, because a [custodian](eval-model.html#%28tech._custodian%29) shut down could terminate the thread. As a result, a thread blocking with [thread-wait](#%28def._%28%28quote._~23~25kernel%29._thread-wait%29%29) normally cannot be garbage collected (see [Garbage Collection](eval-model.html#%28part._gc-model%29)). As a special case, however, ([thread-wait](#%28def._%28%28quote._~23~25kernel%29._thread-wait%29%29) thd) blocks without preventing garbage collection of the thread if thd is the current thread, since the thread could only continue if a break escapes from the wait.

Changed in version 8.18.0.2 of package base: Added support for threads with values and the fail-k argument.

> ```
(thread-dead-evt thd)  →  evt?
  thd : thread?
```


# 10.4 Continuations
Returns a synchronizable event (see Events) that is ready for synchronization if and only if thd has terminated. Unlike using thd directly, however, retaining a reference to the event does not prevent thd from being garbage collected (see Garbage Collection). The synchronization result of a thread-dead event is the thread-dead event itself.
A thread waiting on the result of (thread-dead-evt thd) normally cannot itself be garbage collected, unless thd was created with thread/suspend-to-kill, along the same lines as waiting via thread-wait. However, there is no special case for waiting on the result of (thread-dead-evt thd) where thd is the current thread.
For a given thd, thread-dead-evt always returns the same (i.e., eq?) result.
> ```
(thread-resume-evt thd)   →   evt?
  thd : thread?```


# 10.4 Continuations
Returns a [synchronizable event](sync.html#%28tech._synchronizable._event%29) (see [Events](sync.html)) that becomes [ready for synchronization](sync.html#%28tech._ready._for._synchronization%29) when thd is running. (If thd has terminated, the event never becomes ready.) If thd runs and is then suspended after a call to [thread-resume-evt](#%28def._%28%28quote._~23~25kernel%29._thread-resume-evt%29%29), the result event remains ready; after each suspend of thd a fresh event is generated to be returned by [thread-resume-evt](#%28def._%28%28quote._~23~25kernel%29._thread-resume-evt%29%29). The result of the event is thd, but if thd is never resumed, then reference to the event does not prevent thd from being garbage collected (see [Garbage Collection](eval-model.html#%28part._gc-model%29)).
> ```
(thread-suspend-evt thd)  →  evt?
  thd : thread?


# 10.4 Continuations
```
Returns a synchronizable event (see Events) that becomes ready for synchronization when thd is suspended. (If thd has terminated, the event will never unblock.) If thd is suspended and then resumes after a call to thread-suspend-evt, the result event remains ready; each resume of thd creates a fresh event to be returned by thread-suspend-evt. The result of the event is thd, but if thd was created with thread (as opposed to thread/suspend-to-kill) and is never resumed, then reference to the event does not prevent thd from being garbage collected (see Garbage Collection).

If thd was created with thread/suspend-to-kill, then waiting on (thread-suspend-evt thd) prevents garbage collection of the waiting thread in the same way as (thread-dead-evt another-thd) for a another-thd created via thread. Furthermore, since the event result is thd, waiting on (thread-suspend-evt thd) prevents garbage collection of thd.

#### 11.1.4 Thread Mailboxes

Each thread has a mailbox through which it can receive arbitrary messages. In other words, each thread has a built-in asynchronous channel.

> > > <img src="magnify.png" width="24" height="24" alt="+" />See also Buffered Asynchronous Channels.

> ```
(thread-send thd v [fail-thunk) → any
  thd : thread?
  v : any/c
   fail-thunk   :   (or/c (  →   any) #f)
      =   (lambda () (raise-mismatch-error ....))```

Queues v as a message to thd without blocking. If the message is queued, the result is [#<void>](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=guide&rel=void_undefined.html&version=8.18.0.13). If thd stops running—as in [thread-running?](#%28def._%28%28quote._~23~25kernel%29._thread-running~3f%29%29)—before the message is queued, then fail-thunk is called (through a tail call) if it is a procedure to produce the result, or #f is returned if fail-thunk is #f.

> ```
(thread-receive)  →  any/c
```


# 10.4 Continuations
Receives and dequeues a message queued for the current thread, if any. If no message is available, thread-receive blocks until one is available.
> ```
(thread-try-receive)   →   any/c```
Receives and dequeues a message queued for the current thread, if any, or returns #f immediately if no message is available.
> ```
(thread-receive-evt)  →  evt?
```
(parameter)	→```

Pushes the elements of lst back onto the front of the current thread’s queue. The elements are pushed one by one, so that the first available message is the last element of lst.

#### 11.1.5 Parallel Thread Pools

> ```
(parallel-thread-pool? v)  →  thread?
  v : any/c
```
Returns #t if v is a parallel thread pool, #f otherwise.
Added in version 8.18.0.2 of package base.
> ```
(make-parallel-thread-pool [n) → parallel-thread-pool?
  n : exact-positive-integer? = (processor-count)```
Creates a parallel thread pool that can be used to group a [parallel thread](eval-model.html#%28tech._parallel._thread%29) with other parallel threads. The threads in a pool can use up to n processors to run. If more than n threads are in the pool, not all of them will run in parallel, but they will still all run concurrently.


# 10.4 Continuations
The new thread pool is placed into the management of the current [custodian](eval-model.html#%28tech._custodian%29). If the custodian is shut down, then the pool is closed in the same way as with [parallel-thread-pool-close](#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._parallel-thread-pool-close%29%29), but in addition, no parallel threads in the pool will be able to continue. The threads will not count as terminated (since each thread has its own custodians for that purpose), but they will cease to make progress.
A parallel thread pool cannot run threads in parallel on the [BC](implementations.html#%28tech._bc%29) variant of Racket or when Racket is compiled without support for parallelism. In that case, parallel threads behave the same as [coroutine threads](eval-model.html#%28tech._coroutine._thread%29). For the [CS](implementations.html#%28tech._c%29) variant of Racket, the [futures-enabled?](futures.html#%28def._%28%28lib._racket%2Ffuture..rkt%29._futures-enabled~3f%29%29) predicate can be used to detect when parallel threads behave differently from coroutine threads.
Added in version 8.18.0.2 of package base.
> ```
(parameter)	→


# 10.4 Continuations
```
Closes a parallel thread pool so that no threads can be added to the pool. Any existing threads in the pool are allowed to continue running, and they continue to share the pool’s processor resources.

When no more threads are running within a closed thread pool, or when no threads are allowed to make progress because the pool’s custodian has been shut down, then processor resources allocated to the pool can be returned to the operating system (i.e., operating-system threads allocated to the pool are terminated).

Added in version 8.18.0.2 of package base.

------------------------------------------------------------------------

# 11.2 Synchronization

### 11.2 Synchronization

Racket’s synchronization toolbox spans four layers:

-  synchronizable events — a general framework for synchronization;

-  channels — a primitive that can be used, in principle, to build most other kinds of synchronizable events (except the ones that compose events); and

-  semaphores — a simple and especially cheap primitive for synchronization.

-  future semaphores — a simple synchronization primitive for use with futures.

|  |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|     11.2.1 Events  |
|     11.2.2 Channels  |
|     11.2.3 Semaphores  |
|     11.2.4 Buffered Asynchronous Channels  |
|       11.2.4.1 Creating and Using Asynchronous Channels  |
|       11.2.4.2 Contracts and Impersonators on Asynchronous Channels |

------------------------------------------------------------------------

# 11.2.1 Events

#### 11.2.1 Events

A synchronizable event (or just event for short) works with the sync procedure to coordinate synchronization among threads. Certain kinds of objects double as events, including ports and threads. Other kinds of objects exist only for their use as events. Racket’s event system is based on Concurrent ML \[Reppy99\].

At any point in time, an event is either ready for synchronization, or it is not; depending on the kind of event and how it is used by other threads, an event can switch from not ready to ready (or back), at any time. If a thread synchronizes on an event when it is ready, then the event produces a particular synchronization result.

Synchronizing an event may affect the state of the event. For example, when synchronizing a semaphore, then the semaphore’s internal count is decremented, just as with semaphore-wait. For most kinds of events, however (such as a port), synchronizing does not modify the event’s state.

Racket values that act as synchronizable events include asynchronous channels, channels, custodian boxes, log receivers, place channels, ports, semaphores, subprocesses, TCP listeners, threads, and will executors. Libraries can define new synchronizable events, especially though prop:evt.

> ```
(evt? v) → boolean?
  v : any/c```

Returns #t if v is a [synchronizable event](#%28tech._synchronizable._event%29), #f otherwise.

Examples:

> ```racket
> > ( evt? never-evt )
> #t
> > ( evt? ( make-channel ) )
> #t
> > ( evt? 5 )
> #f
> ```

> ```
(sync evt ...) → any
  evt : evt?
```


# 10.4 Continuations
(parameter)	→
(-> or/c #f (and/c real? (not/c negative?)) (→ any))```
Like [sync](#%28def._%28%28quote._~23~25kernel%29._sync%29%29) if timeout is #f. If timeout is a real number, then the result is #f if timeout seconds pass without a successful synchronization. If timeout is a procedure, then it is called in tail position if polling the evts discovers no ready events.
A zero value for timeout is equivalent to ([lambda](lambda.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._lambda%29%29) () #f). In either case, each evt is checked at least once before returning #f or calling timeout.
See also [alarm-evt](#%28def._%28%28quote._~23~25kernel%29._alarm-evt%29%29) for an alternative timeout mechanism.
Examples:
> ```racket
> ; times out before waking up
> > ( sync/timeout 0.5 ( thread ( λ ( ) ( sleep 1 ) ( displayln "woke up!" ) ) ) )
> #f
> > ( sync/timeout ( λ ( ) ( displayln "no ready events" ) ) never-evt )
> no ready events
> ```
Changed in version 6.1.0.3 of package base: Allow 1 argument instead of 2 or more.
> ```
(sync/enable-break evt ...) → any
  evt : evt?


# 10.4 Continuations
```
Like sync, but breaking is enabled (see Breaks) while waiting on the evts. If breaking is disabled when sync/enable-break is called, then either all evts remain unchosen or the exn:break exception is raised, but not both.

> ```
(sync/timeout/enable-break timeout evt ...) → any
  timeout : (or/c #f (and/c real? (not/c negative?)) (  →   any))
  evt : evt?```

Like [sync/enable-break](#%28def._%28%28quote._~23~25kernel%29._sync%2Fenable-break%29%29), but with a timeout as for [sync/timeout](#%28def._%28%28quote._~23~25kernel%29._sync%2Ftimeout%29%29).

> ```
(choice-evt evt ...) → evt?
  evt : evt?
```
Creates and returns a single event that combines the evts. Supplying the result to sync is the same as supplying each evt to the same call.
That is, an event returned by choice-evt is ready for synchronization when one or more of the evts supplied to choice-evt are ready for synchronization. If the choice event is chosen, one of its ready evts is chosen pseudo-randomly, and the synchronization result is the chosen evt’s synchronization result.
Examples:
> ```racket
> > ( define ch1 ( make-channel ) )
> > ( define ch2 ( make-channel ) )
> > ( define either-channel ( choice-evt ch1 ch2 ) )
> > ( thread ( λ ( ) ( displayln ( sync either-channel ) ) ) )
> #<thread>
> > ( channel-put ( if ( > ( random ) 0.5 ) ch1 ch2 ) ' tuturuu )
> tuturuu
> ```
> ```
(wrap-evt evt wrap) → evt?
  evt : evt?
  wrap : (any/c ... .  →  . any)```


# 10.4 Continuations
Creates an event that is [ready for synchronization](#%28tech._ready._for._synchronization%29) when evt is [ready for synchronization](#%28tech._ready._for._synchronization%29), but whose [synchronization result](#%28tech._synchronization._result%29) is determined by applying wrap to the [synchronization result](#%28tech._synchronization._result%29) of evt. The number of arguments accepted by wrap must match the number of values for the synchronization result of evt.
The call to wrap is [parameterize-break](breakhandler.html#%28form._%28%28lib._racket%2Fprivate%2Fmore-scheme..rkt%29._parameterize-break%29%29)ed to disable breaks initially.
Examples:
> ```racket
> > ( define ch ( make-channel ) )
> > ( define evt ( wrap-evt ch ( λ ( v ) ( format "you've got mail: ~a" v ) ) ) )
> > ( thread ( λ ( ) ( displayln ( sync evt ) ) ) )
> #<thread>
> > ( channel-put ch "Dear Alice ..." )
> you've got mail: Dear Alice ...
> ```
> ```
(handle-evt evt handle) → handle-evt?
  evt : evt?
  handle : (any/c ... .  →  . any)


# 10.4 Continuations
```
Like wrap-evt, except that handle is called in tail position with respect to the synchronization request—and without breaks explicitly disabled—when it is not wrapped by wrap-evt, chaperone-evt, or another handle-evt.

Examples:

> ```racket
> > ( define msg-ch ( make-channel ) )
> > ( define exit-ch ( make-channel ) )
> > ( thread ( λ ( ) ( let loop ( [ val 0 ] ) ( printf "val = ~a~n" val ) ( sync ( handle-evt msg-ch ( λ ( val ) ( loop val ) ) ) ( handle-evt exit-ch ( λ ( val ) ( displayln val ) ) ) ) ) ) )
> val = 0
> #<thread>
> > ( channel-put msg-ch 5 )
> val = 5
> > ( channel-put msg-ch 7 )
> val = 7
> > ( channel-put exit-ch ' done )
> done
> ```

> ```
(guard-evt maker) → evt?
  maker : (  →   (or/c evt? any/c))```

Creates a value that behaves as an event, but that is actually an event maker.

An event guard returned by [guard-evt](#%28def._%28%28lib._racket%2Fprivate%2Fmisc..rkt%29._guard-evt%29%29) generates an event when guard is used with [sync](#%28def._%28%28quote._~23~25kernel%29._sync%29%29) (or whenever it is part of a choice event used with [sync](#%28def._%28%28quote._~23~25kernel%29._sync%29%29), etc.), where the generated event is the result of calling maker. The maker procedure may be called by [sync](#%28def._%28%28quote._~23~25kernel%29._sync%29%29) at most once for a given call to [sync](#%28def._%28%28quote._~23~25kernel%29._sync%29%29), but maker may not be called if a ready event is chosen before guard is even considered.

If maker returns a non-event, then maker’s result is replaced with an event that is [ready for synchronization](#%28tech._ready._for._synchronization%29) and whose [synchronization result](#%28tech._synchronization._result%29) is guard.

> ```
(nack-guard-evt maker)  →  evt?
  maker : (evt? .  →  . (or/c evt? any/c))
```


# 10.4 Continuations
Like guard-evt, but when maker is called, it is given a NACK (“negative acknowledgment”) event. After starting the call to maker, if the event from maker is not ultimately chosen as the ready event, then the NACK event supplied to maker becomes ready for synchronization with a #<void> value.
The NACK event becomes ready for synchronization when the event is abandoned when either some other event is chosen, the synchronizing thread is dead, or control escapes from the call to sync (even if nack-guard’s maker has not yet returned a value). If the event returned by maker is chosen, then the NACK event never becomes ready for synchronization.
> ```
(poll-guard-evt maker)   →   evt?
  maker : (boolean? .  →  . (or/c evt? any/c))```
Like [guard-evt](#%28def._%28%28lib._racket%2Fprivate%2Fmisc..rkt%29._guard-evt%29%29), but when maker is called, it is provided a boolean value that indicates whether the event will be used for a poll, #t, or for a blocking synchronization, #f.
If #t is supplied to maker, if breaks are disabled, if the polling thread is not terminated, and if polling the resulting event produces a [synchronization result](#%28tech._synchronization._result%29), then the event will certainly be chosen for its result.
> ```
(replace-evt evt maker) → evt?
  evt : evt?
  maker : (any/c ... .  →  . (or/c evt? any/c))


# 10.4 Continuations
```
Like guard-evt, but maker is called only after evt becomes ready for synchronization, and the synchronization result of evt is passed to maker.

The attempt to synchronize on evt proceeds concurrently as the attempt to synchronize on the result guard from replace-evt; despite that concurrency, if maker is called, it is called in the thread that is synchronizing on guard. Synchronization can succeed for both evt and another synchronized with guard at the same time; the single-choice guarantee of synchronization applies only to the result of maker and other events synchronized with guard.

If maker returns a non-event, then maker’s result is replaced with an event that is ready for synchronization and whose synchronization result is guard.

Added in version 6.1.0.3 of package base.

> <table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><blockquote>

<p>value</p>

<p>always-evt : evt?</p></blockquote></td></tr></tbody></table>

A constant event that is always ready for synchronization, with itself as its synchronization result.

Example:

> ```racket
> > ( sync always-evt )
> #<always-evt>
> ```

> <table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><blockquote>

<p>value</p>

<p>never-evt : evt?</p></blockquote></td></tr></tbody></table>

A constant event that is never ready for synchronization.

Example:

> ```racket
> > ( sync/timeout 0.1 never-evt )
> #f
> ```

> ```
(system-idle-evt) → evt?```

Returns an event that is [ready for synchronization](#%28tech._ready._for._synchronization%29) when the system is otherwise idle: if the result event were replaced by [never-evt](#%28def._%28%28quote._~23~25kernel%29._never-evt%29%29), no thread in the system would be available to run. In other words, all threads must be suspended or blocked on events with timeouts that have not yet expired. The system-idle event’s [synchronization result](#%28tech._synchronization._result%29) is [#<void>](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=guide&rel=void_undefined.html&version=8.18.0.13). The result of the [system-idle-evt](#%28def._%28%28quote._~23~25kernel%29._system-idle-evt%29%29) procedure is always the same event.

Examples:

> ```racket
> > ( define th ( thread ( λ ( ) ( let loop ( ) ( loop ) ) ) ) )
> > ( sync/timeout 0.1 ( system-idle-evt ) )
> #f
> > ( kill-thread th )
> > ( sync ( system-idle-evt ) )
> ```

> ```
(alarm-evt msecs [monotonic?) → evt?
  msecs : real?
  monotonic? : any/c = #f
```


# 10.4 Continuations
(milliseconds)	→```
Returns #t if evt was created by [handle-evt](#%28def._%28%28quote._~23~25kernel%29._handle-evt%29%29) or by [choice-evt](#%28def._%28%28quote._~23~25kernel%29._choice-evt%29%29) applied to another event for which [handle-evt?](#%28def._%28%28quote._~23~25kernel%29._handle-evt~3f%29%29) produces #t. For any other event, [handle-evt?](#%28def._%28%28quote._~23~25kernel%29._handle-evt~3f%29%29) produces #f.
Examples:
> ```racket
> > ( handle-evt? never-evt )
> #f
> > ( handle-evt? ( handle-evt always-evt values ) )
> #t
> ```
>
<colgroup><col style="width: 100%" /></colgroup>

value

[prop:evt](#%28def._%28%28quote._~23~25kernel%29._prop~3aevt%29%29) : [struct-type-property?](structprops.html#%28def._%28%28quote._~23~25kernel%29._struct-type-property~3f%29%29)

A [structure type property](structprops.html#%28tech._structure._type._property%29) that identifies structure types whose instances can serve as [synchronizable events](#%28tech._synchronizable._event%29). The property value can be any of the following:
-   An event evt: In this case, using the structure as an event is equivalent to using evt.


# 10.4 Continuations
-   A procedure proc of one argument: In this case, the structure is similar to an event generated by [guard-evt](#%28def._%28%28lib._racket%2Fprivate%2Fmisc..rkt%29._guard-evt%29%29), except that the would-be guard procedure proc receives the structure as an argument, instead of no arguments; also, a non-event result from proc is replaced with an event that is already [ready for synchronization](#%28tech._ready._for._synchronization%29) and whose [synchronization result](#%28tech._synchronization._result%29) is the structure.
-   An exact, non-negative integer between 0 (inclusive) and the number of non-automatic fields in the structure type (exclusive, not counting supertype fields): The integer identifies a field in the structure, and the field must be designated as immutable. If the field contains an object or an event-generating procedure of one argument, the event or procedure is used as above. Otherwise, the structure acts as an event that is never ready.
> > > For working with foreign libraries, a [prop:evt](#%28def._%28%28quote._~23~25kernel%29._prop~3aevt%29%29) value can also be a result of [unsafe-poller](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=foreign&rel=Thread_Scheduling.html%23%2528def._%2528%2528lib._ffi%252Funsafe%252Fschedule..rkt%2529._unsafe-poller%2529%2529&version=8.18.0.13), although that possibility is omitted from the safe contract of [prop:evt](#%28def._%28%28quote._~23~25kernel%29._prop~3aevt%29%29).


# 10.4 Continuations
Instances of a structure type with the [prop:input-port](portstructs.html#%28def._%28%28quote._~23~25kernel%29._prop~3ainput-port%29%29) or [prop:output-port](portstructs.html#%28def._%28%28quote._~23~25kernel%29._prop~3aoutput-port%29%29) property are also [synchronizable events](#%28tech._synchronizable._event%29) by virtue of being a port. If the structure type has more than one of [prop:evt](#%28def._%28%28quote._~23~25kernel%29._prop~3aevt%29%29), [prop:input-port](portstructs.html#%28def._%28%28quote._~23~25kernel%29._prop~3ainput-port%29%29), and [prop:output-port](portstructs.html#%28def._%28%28quote._~23~25kernel%29._prop~3aoutput-port%29%29), then the [prop:evt](#%28def._%28%28quote._~23~25kernel%29._prop~3aevt%29%29) value (if any) takes precedence for determining the instance’s behavior as an event, and the [prop:input-port](portstructs.html#%28def._%28%28quote._~23~25kernel%29._prop~3ainput-port%29%29) property takes precedence over [prop:output-port](portstructs.html#%28def._%28%28quote._~23~25kernel%29._prop~3aoutput-port%29%29) for synchronization.
Examples:


# 10.4 Continuations
> ```racket
> > ( struct wt ( base val ) #:property prop:evt ( struct-field-index base ) )
> > ( define sema ( make-semaphore ) )
> > ( sync/timeout 0 ( wt sema #f ) )
> #f
> > ( semaphore-post sema )
> > ( sync/timeout 0 ( wt sema #f ) )
> #<semaphore>
> > ( semaphore-post sema )
> > ( sync/timeout 0 ( wt ( lambda ( self ) ( wt-val self ) ) sema ) )
> #<semaphore>
> > ( semaphore-post sema )
> > ( define my-wt ( wt ( lambda ( self ) ( wrap-evt ( wt-val self ) ( lambda ( x ) self ) ) ) sema ) )
> > ( sync/timeout 0 my-wt )
> #<wt>
> > ( sync/timeout 0 my-wt )
> #f
> ```
> ```
(current-evt-pseudo-random-generator)	→
(-> current-evt-pseudo-random-generator generator)
(current-evt-pseudo-random-generator generator) → void?
    generator	:
(-> current-evt-pseudo-random-generator generator)
```
(atomic)	→```

Returns #t if v is a [channel](#%28tech._channel%29), #f otherwise.

> ```
(make-channel)  →  channel?
```
Creates and returns a new channel. The channel can be used with channel-get, with channel-try-get, or as a synchronizable event (see Events) to receive a value through the channel. The channel can be used with channel-put or through the result of channel-put-evt to send a value through the channel.
> ```
(channel-get ch)   →   any
  ch : channel?```
Blocks until a sender is ready to provide a value through ch. The result is the sent value.
> ```
(channel-try-get ch)  →  any
  ch : channel?


# 10.4 Continuations
```
(parameter)	→```

Blocks until a receiver is ready to accept the value v through ch.

> ```
(channel-put-evt ch v)  →  channel-put-evt?
  ch : channel?
  v : any/c
```
Returns a fresh synchronizable event for use with sync. The event is ready for synchronization when (channel-put ch v) would not block, and the event’s synchronization result is the event itself.
> ```
(channel-put-evt? v)   →   boolean?
  v : any/c```
Returns #t if v is a channel-put event produced by [channel-put-evt](#%28def._%28%28quote._~23~25kernel%29._channel-put-evt%29%29), #f otherwise.
------------------------------------------------------------------------


# 11.2.3 Semaphores


#### 11.2.3 Semaphores
A semaphore has an internal counter; when this counter is zero, the semaphore can block a thread’s execution (through [semaphore-wait](#%28def._%28%28quote._~23~25kernel%29._semaphore-wait%29%29)) until another thread increments the counter (using [semaphore-post](#%28def._%28%28quote._~23~25kernel%29._semaphore-post%29%29)). The maximum value for a semaphore’s internal counter is platform-specific, but always at least 10000.
A semaphore’s counter is updated in a single-threaded manner, so that semaphores can be used for reliable synchronization. Semaphore waiting is fair: if a thread is blocked on a semaphore and the semaphore’s internal value is non-zero infinitely often, then the thread is eventually unblocked.
In addition to its use with semaphore-specific procedures, a semaphore can be used as a [synchronizable event](sync.html#%28tech._synchronizable._event%29) (see [Events](sync.html)). A semaphore is [ready for synchronization](sync.html#%28tech._ready._for._synchronization%29) when [semaphore-wait](#%28def._%28%28quote._~23~25kernel%29._semaphore-wait%29%29) would not block. Upon synchronization, the semaphore’s counter is decremented, and the [synchronization result](sync.html#%28tech._synchronization._result%29) of a semaphore is the semaphore itself.
> ```
(semaphore? v)  →  boolean?
  v : any/c


# 11.2.3 Semaphores
```
Returns #t if v is a semaphore, #f otherwise.

> ```
(make-semaphore [init) → semaphore?
  init : exact-nonnegative-integer? = 0```

Creates and returns a new semaphore with the counter initially set to init. If init is larger than a semaphore’s maximum internal counter value, the [exn:fail](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3afail%29%29) exception is raised.

> ```
(parameter)	→
```
(parameter)	→```
Blocks until the internal counter for semaphore sema is non-zero. When the counter is non-zero, it is decremented and [semaphore-wait](#%28def._%28%28quote._~23~25kernel%29._semaphore-wait%29%29) returns [#<void>](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=guide&rel=void_undefined.html&version=8.18.0.13).
> ```
(semaphore-try-wait? sema)  →  boolean?
  sema : semaphore?
```
(parameter)	→```

Like [semaphore-wait](#%28def._%28%28quote._~23~25kernel%29._semaphore-wait%29%29), but breaking is enabled (see [Breaks](breakhandler.html)) while waiting on sema. If breaking is disabled when [semaphore-wait/enable-break](#%28def._%28%28quote._~23~25kernel%29._semaphore-wait%2Fenable-break%29%29) is called, then either the semaphore’s counter is decremented or the [exn:break](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3abreak%29%29) exception is raised, but not both.

> ```
(semaphore-peek-evt sema)  →  semaphore-peek-evt?
  sema : semaphore?
```


# 11.2.3 Semaphores
Creates and returns a new synchronizable event (for use with sync, for example) that is ready for synchronization when sema is ready, but synchronizing the event does not decrement sema’s internal count. The synchronization result of a semaphore-peek event is the semaphore-peek event itself.
> ```
(semaphore-peek-evt? v)   →   boolean?
  v : any/c```
Returns #t if v is a semaphore wrapper produced by [semaphore-peek-evt](#%28def._%28%28quote._~23~25kernel%29._semaphore-peek-evt%29%29), #f otherwise.
> ```
(call-with-semaphore sema
    proc
   [ try-fail-thunk]
    arg ...)    →    any
  sema : semaphore?
  proc : procedure?
  try-fail-thunk : (or/c (  →   any) #f) = #f
  arg : any/c


# 11.2.3 Semaphores
```
Waits on sema using semaphore-wait, calls proc with all args, and then posts to sema. A continuation barrier blocks full continuation jumps into or out of proc (see Prompts, Delimited Continuations, and Barriers), but escape jumps are allowed, and sema is posted on escape. If try-fail-thunk is provided and is not #f, then semaphore-try-wait? is called on sema instead of semaphore-wait, and try-fail-thunk is called if the wait fails.

> ```
(call-with-semaphore/enable-break sema
    proc
   [ try-fail-thunk]
    arg ...)    →    any

  sema : semaphore?
  proc : procedure?
  try-fail-thunk : (or/c (  →   any) #f) = #f
  arg : any/c```

Like [call-with-semaphore](#%28def._%28%28quote._~23~25kernel%29._call-with-semaphore%29%29), except that [semaphore-wait/enable-break](#%28def._%28%28quote._~23~25kernel%29._semaphore-wait%2Fenable-break%29%29) is used with sema in non-try mode. When try-fail-thunk is provided and not #f, then breaks are enabled around the use of [semaphore-try-wait?](#%28def._%28%28quote._~23~25kernel%29._semaphore-try-wait~3f%29%29) on sema.

------------------------------------------------------------------------

# 11.2.4 Buffered Asynchronous Channels

#### 11.2.4 Buffered Asynchronous Channels

|                                                                                |                                                                                |
|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------:|
|  ([require](require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._require%29%29) [racket/async-channel]()) |  package: [base](https://pkgs.racket-lang.org/package/base "Install this package using `raco pkg install base`") |

The bindings documented in this section are provided by the [racket/async-channel]() library, not [racket/base](index.html) or [racket](index.html).

##### 11.2.4.1 Creating and Using Asynchronous Channels

> > > <img src="magnify.png" width="24" height="24" alt="+" />See also [Thread Mailboxes](threads.html#%28part._threadmbox%29).

An asynchronous channel is like a [channel](channel.html#%28tech._channel%29), but it buffers values so that a send operation does not wait on a receive operation.

In addition to its use with procedures that are specific to asynchronous channels, an asynchronous channel can be used as a [synchronizable event](sync.html#%28tech._synchronizable._event%29) (see [Events](sync.html)). An asynchronous channel is [ready for synchronization](sync.html#%28tech._ready._for._synchronization%29) when [async-channel-get](#%28def._%28%28lib._racket%2Fasync-channel..rkt%29._async-channel-get%29%29) would not block; the asynchronous channel’s [synchronization result](sync.html#%28tech._synchronization._result%29) is the same as the [async-channel-get](#%28def._%28%28lib._racket%2Fasync-channel..rkt%29._async-channel-get%29%29) result.

> ```
(async-channel? v)  →  boolean?
  v : any/c
```


# 11.2.3 Semaphores
Returns #t if v is an asynchronous channel, #f otherwise.
> ```
(make-async-channel [limit) → async-channel?
  limit : (or/c exact-positive-integer? #f) = #f```
Returns an asynchronous channel with a buffer limit of limit items. A get operation blocks when the channel is empty, and a put operation blocks when the channel has limit items already. If limit is #f, the channel buffer has no limit (so a put never blocks).
> ```
(async-channel-get ach)  →  any/c
  ach : async-channel?
```

Blocks until at least one value is available in ach, and then returns the first of the values that were put into async-channel.

> ```
(async-channel-try-get ach)  →  any/c
  ach : async-channel?
```
If at least one value is immediately available in ach, returns the first of the values that were put into ach. If async-channel is empty, the result is #f.
> ```
(parameter)	→
```

Puts v into ach, blocking if ach’s buffer is full until space is available.

> ```
(async-channel-put-evt ach v)  →  evt?
  ach : async-channel?
  v : any/c
```
Returns a [synchronizable event](sync.html#%28tech._synchronizable._event%29) that is [ready for synchronization](sync.html#%28tech._ready._for._synchronization%29) when ([async-channel-put](#%28def._%28%28lib._racket%2Fasync-channel..rkt%29._async-channel-put%29%29) ach v) would return a value (i.e., when the channel holds fewer values already than its limit); the [synchronization result](sync.html#%28tech._synchronization._result%29) of a asynchronous channel-put event is the asynchronous channel-put event itself.
Examples: