Cond
Cond
implements a condition variable, a rendezvous point for an operation waiting for or announcing the occurrence of an event.
Each Cond
has an associated Mutex
, which must be held when changing the condition and when calling the wait
method.
-
Returns a new Cond. - Parameter mutex: A Mutex object.
Declaration
Swift
public init(_ mutex : Mutex)
-
Wakes all operations waiting on
Cond
.Declaration
Swift
public func broadcast()
-
Wakes one operations waiting on
Cond
.Declaration
Swift
public func signal()
-
Atomically unlocks
.mutex
and suspends execution of the calling operation. After later resuming execution,waita locks
.mutex’ before returning. Unlike in other systems,wait
cannot return unless awoken bybroadcast
orsignal', or the
timeout` param has been reached.Because
.mutex
is not locked when ‘wait first resumes, the caller typically cannot assume that the condition is true whenwait
returns. Instead, the caller shouldwait
in a loop:cond.mutex.lock() while !condition() { cond.mutex.wait() } ... make use of condition ... cond.mutex.unlock()
Declaration
Swift
public func wait(timeout : NSTimeInterval = -1) -> WaitResult