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 by broadcast or signal', or thetimeout` param has been reached.

    Because .mutex 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:

    cond.mutex.lock()
    while !condition() {
        cond.mutex.wait()
    }
    ... make use of condition ...
    cond.mutex.unlock()
    

    Declaration

    Swift

    public func wait(timeout : NSTimeInterval = -1) -> WaitResult