- 论坛徽章:
- 89
|
本帖最后由 fender0107401 于 2016-04-20 15:53 编辑
刚才仔细看了一下这个method的doc,感觉写的好清楚啊。
http://www.boost.org/doc/libs/1_ ... ition_variable.wait
void wait(boost::unique_lock<boost::mutex>& lock)
Precondition:
lock is locked by the current thread, and either no other thread is currently waiting on *this, or the execution of the mutex() member function on the lock objects supplied in the calls to wait or timed_wait in all the threads currently waiting on *this would return the same value as lock->mutex() for this call to wait.
Effects:
Atomically call lock.unlock() and blocks the current thread. The thread will unblock when notified by a call to this->notify_one() or this->notify_all(), or spuriously. When the thread is unblocked (for whatever reason), the lock is reacquired by invoking lock.lock() before the call to wait returns. The lock is also reacquired by invoking lock.lock() if the function exits with an exception.
Postcondition:
lock is locked by the current thread.
Throws:
boost::thread_resource_error if an error occurs. boost::thread_interrupted if the wait was interrupted by a call to interrupt() on the boost::thread object associated with the current thread of execution.
再看看Qt里面的,感觉写的东西是一样的,但是没有Boost里面的写的清楚。
http://doc.qt.io/qt-5/qwaitcondition.html#wait
bool QWaitCondition::wait(QMutex *lockedMutex, unsigned long time = ULONG_MAX)
Releases the lockedMutex and waits on the wait condition. The lockedMutex must be initially locked by the calling thread. If lockedMutex is not in a locked state, the behavior is undefined. If lockedMutex is a recursive mutex, this function returns immediately. The lockedMutex will be unlocked, and the calling thread will block until either of these conditions is met:
- Another thread signals it using wakeOne() or wakeAll(). This function will return true in this case.
- time milliseconds has elapsed. If time is ULONG_MAX (the default), then the wait will never timeout (the event must be signalled). This function will return false if the wait timed out.
The lockedMutex will be returned to the same locked state. This function is provided to allow the atomic transition from the locked state to the wait state.
See also wakeOne() and wakeAll(). |
|