Scheduler-context wait queue with explicit wake-all and wake-one operations. The Signal wrapper stores no persistent boolean state and remembers no prior wake.


Signal model


Signal

Methods

INIT

(--) Performs no operation.

wait

(--) Blocks until wake or wakeOne releases the current context, unless the current context is already canceled.

wake

(--) Wakes every currently waiting context.

wakeOne

(--) Wakes the oldest currently waiting context.

Waiting and cancellation semantics


Examples

FIFO wakeOne order

"String"      use
"control"     use
"sync/Signal" use
"sync/sync"   use

{} Int32 {} [
  signal: Signal;
  one: {signal: @signal; CALL: [
    @signal.wait
    ("one" LF) printList
  ];} () spawn;
  two: {signal: @signal; CALL: [
    @signal.wait
    ("two" LF) printList
  ];} () spawn;
  yield
  @signal.wakeOne
  yield
  @signal.wakeOne
  @one.wait
  @two.wait
  0
] "main" exportFunction

Expected Output

one
two

Wake is not remembered

"String"      use
"control"     use
"sync/Signal" use
"sync/sync"   use

{} Int32 {} [
  signal: Signal;
  @signal.wake
  context: {signal: @signal; CALL: [
    @signal.wait
    ("released" LF) printList
  ];} () spawn;
  yield
  context.done? [
    ("done" LF) printList
  ] [
    ("waiting" LF) printList
  ] if
  @signal.wakeOne
  @context.wait
  0
] "main" exportFunction

Expected Output

waiting
released

See also