2 Event Objects
dxtr edited this page 2026-10-11 18:09:35 +02:00

Event Objects

An event object is a flag in the kernel: one thread sets it, others wait for it. It is how a thread with a message loop can wake a thread that waits for its results, without a Lisp condition variable.

(win32:with-event (event)
  (start-work-that-calls-set-event-when-done event)
  (if (win32:wait-for-event event 5)
      :done
      :timed-out))
  • make-event makes one. By default it is auto-reset: waking one waiting thread unsignals it again. With :manual-reset t it stays signalled until reset-event. :signalled t makes it signalled from the start.
  • set-event signals it, and allocates nothing.
  • reset-event unsignals it.
  • wait-for-event waits at most a timeout, in seconds, any non-negative real, or forever for nil, the default. It returns true if the event was signalled, false if the time ran out. A timeout of 0 only looks.
  • close-event releases it; with-event makes one and releases it on leaving.

An event may be used from any thread. The wait happens in Windows, as a foreign call; on SBCL for Windows, a thread in a foreign call does not hold up the garbage collector.