Documentation ¶
Index ¶
- type ConditionVariable
- func (c *ConditionVariable) Broadcast()
- func (c *ConditionVariable) Signal()
- func (c *ConditionVariable) Wait(lck sync.Locker)
- func (c *ConditionVariable) WaitContext(ctx context.Context, lck sync.Locker) error
- func (c *ConditionVariable) WaitFor(lck sync.Locker, timeout time.Duration) error
- func (c *ConditionVariable) WaitForPred(lck sync.Locker, timeout time.Duration, pred func() bool) bool
- func (c *ConditionVariable) WaitPred(lck sync.Locker, pred func() bool)
- func (c *ConditionVariable) WaitPredContext(ctx context.Context, lck sync.Locker, pred func() bool) bool
- func (c *ConditionVariable) WaitUntil(lck sync.Locker, d time.Time) error
- func (c *ConditionVariable) WaitUntilPred(lck sync.Locker, d time.Time, pred func() bool) bool
- type Subject
- type TimeoutCond
- func (c *TimeoutCond) Broadcast()
- func (c *TimeoutCond) Signal()
- func (c *TimeoutCond) Wait()
- func (c *TimeoutCond) WaitContext(ctx context.Context) error
- func (c *TimeoutCond) WaitFor(timeout time.Duration) error
- func (c *TimeoutCond) WaitForPred(timeout time.Duration, pred func() bool) bool
- func (c *TimeoutCond) WaitPred(pred func() bool)
- func (c *TimeoutCond) WaitPredContext(ctx context.Context, pred func() bool) bool
- func (c *TimeoutCond) WaitUntil(d time.Time) error
- func (c *TimeoutCond) WaitUntilPred(d time.Time, pred func() bool) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConditionVariable ¶ added in v0.0.150
type ConditionVariable struct {
// contains filtered or unexported fields
}
ConditionVariable is an object able to block the calling thread until notified to resume. see http://www.cplusplus.com/reference/condition_variable/condition_variable/
func (*ConditionVariable) Broadcast ¶ added in v0.0.150
func (c *ConditionVariable) Broadcast()
Broadcast wakes all goroutines waiting on c.
It is allowed but not required for the caller to hold c.L during the call.
func (*ConditionVariable) Signal ¶ added in v0.0.150
func (c *ConditionVariable) Signal()
Signal wakes one goroutine waiting on c, if there is any.
It is allowed but not required for the caller to hold c.L during the call.
func (*ConditionVariable) Wait ¶ added in v0.0.150
func (c *ConditionVariable) Wait(lck sync.Locker)
Wait atomically unlocks c.L and suspends execution of the calling goroutine. After later resuming execution, Wait locks c.L before returning. Unlike in other systems, Wait cannot return unless awoken by Broadcast or Signal.
Because c.L is not locked when Wait first resumes, the caller typically cannot assume that the condition is true when Wait returns. Instead, the caller should Wait in a loop:
c.L.Lock() for !condition() { c.Wait() } ... make use of condition ... c.L.Unlock()
Wait wait until notified
func (*ConditionVariable) WaitContext ¶ added in v0.0.150
WaitContext wait until notified or time point The execution of the current thread (which shall have locked lck's mutex) is blocked either until notified or until ctx done, whichever happens first.
func (*ConditionVariable) WaitFor ¶ added in v0.0.150
WaitFor The execution of the current goroutine (which shall have locked lck's mutex) is blocked during rel_time, or until notified (if the latter happens first). WaitFor wait for timeout or until notified It behaves as if implemented as: return wait_until (lck, chrono::steady_clock::now() + rel_time);
func (*ConditionVariable) WaitForPred ¶ added in v0.0.150
func (c *ConditionVariable) WaitForPred(lck sync.Locker, timeout time.Duration, pred func() bool) bool
WaitForPred wait for timeout or until notified If pred is nil, do as pred returns false always, If pred is specified, the function only blocks if pred returns false, and notifications can only unblock the thread when it becomes true (which is especially useful to check against spurious wake-up calls). It behaves as if implemented as: return wait_until (lck, chrono::steady_clock::now() + rel_time, std::move(pred));
func (*ConditionVariable) WaitPred ¶ added in v0.0.150
func (c *ConditionVariable) WaitPred(lck sync.Locker, pred func() bool)
WaitPred wait until notified If pred is specified (2), the function only blocks if pred returns false, and notifications can only unblock the thread when it becomes true (which is specially useful to check against spurious wake-up calls). This version (2) behaves as if implemented as: while (!pred()) wait(lck);
func (*ConditionVariable) WaitPredContext ¶ added in v0.0.150
func (c *ConditionVariable) WaitPredContext(ctx context.Context, lck sync.Locker, pred func() bool) bool
WaitPredContext wait until notified or ctx done The execution of the current thread (which shall have locked lck's mutex) is blocked either until notified or until ctx, whichever happens first. If pred is nil, do as pred returns false always, If pred is specified, the function only blocks if pred returns false, and notifications can only unblock the thread when it becomes true (which is especially useful to check against spurious wake-up calls). It behaves as if implemented as: while (!pred())
if ( wait_until(ctx,lck) == cv_status::timeout) return pred();
return true;
func (*ConditionVariable) WaitUntil ¶ added in v0.0.150
WaitUntil wait until notified or time point The execution of the current thread (which shall have locked lck's mutex) is blocked either until notified or until abs_time, whichever happens first.
func (*ConditionVariable) WaitUntilPred ¶ added in v0.0.150
WaitUntilPred wait until notified or ctx done The execution of the current thread (which shall have locked lck's mutex) is blocked either until notified or until ctx, whichever happens first. If pred is nil, do as pred returns false always, If pred is specified, the function only blocks if pred returns false, and notifications can only unblock the thread when it becomes true (which is especially useful to check against spurious wake-up calls). It behaves as if implemented as: while (!pred())
if ( wait_until(lck,abs_time) == cv_status::timeout) return pred();
return true;
type Subject ¶
type Subject struct {
// contains filtered or unexported fields
}
Subject implements a condition variable like with channel, a rendezvous point for goroutines waiting for or announcing the occurrence of an event.
The caller typically cannot assume that the condition is true when Subscribe chan returns. Instead, the caller should Wait in a loop:
time.After(timeout, c.PublishBroadcast()) // for timeout or periodic event c.PublishBroadcast() // for async notify event directly eventC, cancel := c.Subscribe() for !condition() { select{ case event, closed := <- eventC: ... make use of event ... } } ... make use of condition ...
func (*Subject) PublishBroadcast ¶
PublishBroadcast wakes all listeners waiting on c. PublishBroadcast blocks until event is received or dropped. event will be dropped if ctx is Done before event is received.
func (*Subject) PublishSignal ¶
PublishSignal wakes one listener waiting on c, if there is any. PublishSignal blocks until event is received or dropped.
func (*Subject) Subscribe ¶
func (s *Subject) Subscribe() (<-chan interface{}, context.CancelFunc)
Subscribe returns a channel that's closed when awoken by PublishSignal or PublishBroadcast. never be canceled. Successive calls to Subscribe return different values. The close of the Subscribe channel may happen asynchronously, after the cancel function returns.
type TimeoutCond ¶ added in v0.0.150
type TimeoutCond struct { // L is held while observing or changing the condition L sync.Locker // contains filtered or unexported fields }
func NewTimeoutCond ¶ added in v0.0.150
func NewTimeoutCond(l sync.Locker) *TimeoutCond
NewTimeoutCond returns a new TimeoutCond with Locker l.
func (*TimeoutCond) Broadcast ¶ added in v0.0.150
func (c *TimeoutCond) Broadcast()
Broadcast wakes all goroutines waiting on c.
It is allowed but not required for the caller to hold c.L during the call.
func (*TimeoutCond) Signal ¶ added in v0.0.150
func (c *TimeoutCond) Signal()
Signal wakes one goroutine waiting on c, if there is any.
It is allowed but not required for the caller to hold c.L during the call.
func (*TimeoutCond) Wait ¶ added in v0.0.150
func (c *TimeoutCond) Wait()
Wait atomically unlocks c.L and suspends execution of the calling goroutine. After later resuming execution, Wait locks c.L before returning. Unlike in other systems, Wait cannot return unless awoken by Broadcast or Signal.
Because c.L is not locked when Wait first resumes, the caller typically cannot assume that the condition is true when Wait returns. Instead, the caller should Wait in a loop:
c.L.Lock() for !condition() { c.Wait() } ... make use of condition ... c.L.Unlock()
Wait wait until notified
func (*TimeoutCond) WaitContext ¶ added in v0.0.150
func (c *TimeoutCond) WaitContext(ctx context.Context) error
WaitContext wait until notified or time point The execution of the current thread (which shall have locked lck's mutex) is blocked either until notified or until ctx done, whichever happens first.
func (*TimeoutCond) WaitFor ¶ added in v0.0.150
func (c *TimeoutCond) WaitFor(timeout time.Duration) error
WaitFor The execution of the current goroutine (which shall have locked lck's mutex) is blocked during rel_time, or until notified (if the latter happens first). WaitFor wait for timeout or until notified It behaves as if implemented as: return wait_until (lck, chrono::steady_clock::now() + rel_time);
func (*TimeoutCond) WaitForPred ¶ added in v0.0.150
func (c *TimeoutCond) WaitForPred(timeout time.Duration, pred func() bool) bool
WaitForPred wait for timeout or until notified If pred is nil, do as pred returns false always, If pred is specified, the function only blocks if pred returns false, and notifications can only unblock the thread when it becomes true (which is especially useful to check against spurious wake-up calls). It behaves as if implemented as: return wait_until (lck, chrono::steady_clock::now() + rel_time, std::move(pred));
func (*TimeoutCond) WaitPred ¶ added in v0.0.150
func (c *TimeoutCond) WaitPred(pred func() bool)
WaitPred wait until notified If pred is specified (2), the function only blocks if pred returns false, and notifications can only unblock the thread when it becomes true (which is specially useful to check against spurious wake-up calls). This version (2) behaves as if implemented as: while (!pred()) wait(lck);
func (*TimeoutCond) WaitPredContext ¶ added in v0.0.150
func (c *TimeoutCond) WaitPredContext(ctx context.Context, pred func() bool) bool
WaitPredContext wait until notified or ctx done The execution of the current thread (which shall have locked lck's mutex) is blocked either until notified or until ctx, whichever happens first. If pred is nil, do as pred returns false always, If pred is specified, the function only blocks if pred returns false, and notifications can only unblock the thread when it becomes true (which is especially useful to check against spurious wake-up calls). It behaves as if implemented as: while (!pred())
if ( wait_until(ctx,lck) == cv_status::timeout) return pred();
return true;
func (*TimeoutCond) WaitUntil ¶ added in v0.0.150
func (c *TimeoutCond) WaitUntil(d time.Time) error
WaitUntil wait until notified or time point The execution of the current thread (which shall have locked lck's mutex) is blocked either until notified or until abs_time, whichever happens first.
func (*TimeoutCond) WaitUntilPred ¶ added in v0.0.150
func (c *TimeoutCond) WaitUntilPred(d time.Time, pred func() bool) bool
WaitUntilPred wait until notified or time point The execution of the current thread (which shall have locked c.L's mutex) is blocked either until notified or until abs_time, whichever happens first. If pred is nil, do as pred returns false always, If pred is specified, the function only blocks if pred returns false, and notifications can only unblock the thread when it becomes true (which is especially useful to check against spurious wake-up calls). It behaves as if implemented as: while (!pred())
if ( wait_until(lck,abs_time) == cv_status::timeout) return pred();
return true;