struct Syn::Core::ConditionVariable
- Syn::Core::ConditionVariable
- Struct
- Value
- Object
Overview
Synchronize execution of concurrently running fibers.
This can be used to replace polling with a waiting list that can be resumed when resources are available, while still behaving inside a mutually exclusive context: when a waiting fiber is resumed, the lockable will be locked.
Can also be used as a notification system without a lockable. In which case
the lockable must be nil
(or Pointer(Syn::Lockable).null
) and the
lockable won't be unlocked nor locked.
Defined in:
core/condition_variable.crConstructors
Instance Method Summary
-
#broadcast : Nil
Enqueues all waiting fibers at once.
-
#signal : Nil
Enqueues one waiting fiber.
-
#wait(lockable : Pointer(Lockable) | Nil, timeout : Time::Span, *, relock_on_timeout : Bool = true) : Bool
Identical to
#wait
but the current fiber will be resumed automatically whentimeout
is reached.EXPERIMENTAL The timeout feature is experimental.
-
#wait(lockable : Pointer(Lockable) | Nil) : Nil
Suspends the current fiber.
Constructor Detail
Instance Method Detail
Enqueues all waiting fibers at once. Does nothing if there aren't any waiting fiber.
Identical to #wait
but the current fiber will be resumed automatically
when timeout
is reached. Returns true
if the timeout was reached,
false
otherwise.
EXPERIMENTAL The timeout feature is experimental.
Suspends the current fiber. The lockable is unlocked before the fiber is suspended (the current fiber must be holding the lock) and will be locked again after the fiber is resumed and before the function returns.