Condition Variables
condvar?
make-condvar
condvar-signal
condvar-broadcast
condvar-wait-evt
condvar-wait
8.17

Condition Variables🔗ℹ

Bogdan Popa <bogdan@defn.io>

This module provides an implementation of Condition Variables built on top of Racket’s semaphores.

procedure

(condvar? v)  boolean?

  v : any/c

procedure

(make-condvar)  condvar?

The make-condvar procedure returns a new condition variable.

procedure

(condvar-signal cvar)  void?

  cvar : condvar?
Wakes up one of cvar’s waiters.

procedure

(condvar-broadcast cvar)  void?

  cvar : condvar?
Wakes up all of cvar’s waiters.

procedure

(condvar-wait-evt cvar mutex)  (evt/c semaphore?)

  cvar : condvar?
  mutex : semaphore?
Returns a synchronizable event that may become ready for synchronization when the condition variable is signaled. The synchronization result of the event is mutex.

The mutex argument must be a semaphore whose internal counter is zero at the time condvar-wait-evt is called. This procedure increments the mutex internally after adding the waiter to the waitlist, then decrements it once the returned event is selected for synchronization.

procedure

(condvar-wait cvar mutex)  semaphore?

  cvar : condvar?
  mutex : semaphore?
Equivalent to (sync/enable-break (condvar-wait-evt cvar mutex)).