5.10 Thread Scheduling
library provides functions for
cooperating with the thread scheduler and manipulating it. The
library’s operations are unsafe because callbacks run in atomic
and in an unspecified thread.
Added in version 22.214.171.124 of package base.
Produces a poller
value that is allowed as a
value, even though it is not a procedure or itself
. The poll
callback is called in atomic
in an unspecified thread to check whether the event is ready or
to allow it to register a wakeup trigger.
The first argument to poll is always the object that is used
as a synchronizable event with the
poller as its prop:evt value. Let’s call that value
The second argument to poll is #f when poll
is called to check whether the event is ready. The result must be two
values. The first result value is a list of results if evt
is ready, or it is #f if evt is not ready. The
second result value is #f if evt is ready, or it is
an event to replace evt (often just evt itself) if
evt is not ready.
When the thread scheduler has determined that the Racket process
should sleep until an external event or timeout, then poll is
called with a non-#f second argument, wakeups. In
that case, if the first result value is a list, then the sleep will be
canceled, but the list is not recorded as the result (and poll
most likely will be called again). In addition to returning a #f initial
value, poll can call unsafe-poll-ctx-fd-wakeup,
unsafe-poll-ctx-milliseconds-wakeup on wakeups to
register wakeup triggers.
Checks whether the given file descriptor or socket is currently ready
for reading or writing, as selected by mode.
Added in version 126.96.36.199 of package base.
Registers a file descriptor (Unix and Mac OS) or socket (all
platforms) to cause the Racket process to wake up and resume polling
if the file descriptor or socket becomes ready for reading, writing,
or error reporting, as selected by mode
. The wakeups
argument must be a non-#f
value that is passed by the
scheduler to a unsafe-poller
On Windows, registers an eventmask to cause the Racket process to wake
up and resume polling if an event selected by the mask becomes
Causes the Racket process will wake up and resume polling at the point
starts returning a value
that is msecs
Registers foreground-sleep as a procedure to implement
sleeping for the Racket process when the thread scheduler determines
at the process will sleep. Meanwhile, during a call to
foreground-sleep, the scheduler’s default sleeping function
will run in a separate OS-level thread. When that default sleeping
function wakes up, a byte is written to fd as a way of
notifying foreground-sleep that it should return
This function works on when OS-level threads are available within the
Racket implementation. It always works for Mac OS.
For use with unsafe-set-sleep-in-thread!
or something that it triggers, causes the
default sleeping function to request foreground-sleep