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
- A newly constructed
Signal starts with an empty wait queue.
INIT performs no operation.
wake and wakeOne release only contexts that are already waiting.
- No wake is remembered for later waiters.
wait returns no status or result value and exposes no persistent state query.
- A
Signal owns its waiter queue. Destroying a Signal with waiting contexts is invalid.
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
- If the current context is already canceled when
wait begins, wait returns immediately.
- If cancellation happens while the context is already waiting, the context is removed from the wait queue and resumed.
wake affects every currently waiting context.
wakeOne releases the oldest currently waiting context.
- No wake is remembered for later waiters.
Examples
FIFO wakeOne order
"sync/Signal" use
"sync/sync" use
"String" use
"control" 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
"sync/Signal" use
"sync/sync" use
"String" use
"control" 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
- sync/Event: Persistent event state with clear, set, wait, wake, and wakeOne.
- sync/Context: Spawned context handle with waiting, output retrieval, and cancellation.
- sync/sync: Cross-platform scheduling, sleep, time, IPv4 formatting, and TCP helpers.