本文整理汇总了C++中std::condition_variable::notify_all方法的典型用法代码示例。如果您正苦于以下问题:C++ condition_variable::notify_all方法的具体用法?C++ condition_variable::notify_all怎么用?C++ condition_variable::notify_all使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::condition_variable
的用法示例。
在下文中一共展示了condition_variable::notify_all方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Sync
/// Blocks until all N threads reach here
void Sync()
{
std::unique_lock<std::mutex> lock{ m_mutex };
if (m_state == State::Down)
{
// Counting down the number of syncing threads
if (--m_count == 0) {
m_state = State::Up;
m_cv.notify_all();
}
else {
m_cv.wait(lock, [this] { return m_state == State::Up; });
}
}
else // (m_state == State::Up)
{
// Counting back up for Auto reset
if (++m_count == m_initial) {
m_state = State::Down;
m_cv.notify_all();
}
else {
m_cv.wait(lock, [this] { return m_state == State::Down; });
}
}
}
示例2: writeUnlock
/**
* @brief Unlock on writing
*/
void writeUnlock()
{
writing_ = false;
read_cv_.notify_all();
write_cv_.notify_all();
};
示例3: halt
void halt() {
{
std::lock_guard<std::mutex> lk(mutex);
if (!running) return;
running = false;
}
tasks_updated.notify_all();
modified.notify_all();
}
示例4: signals
void signals()
{
std::this_thread::sleep_for(std::chrono::milliseconds(120));
std::cerr << "Notifying...\n";
cv.notify_all();
std::this_thread::sleep_for(std::chrono::milliseconds(100));
i = 1;
std::cerr << "Notifying again...\n";
cv.notify_all();
}
示例5: signals
void signals()
{
wait( 120) ;
std::cerr << "Notifying...\n";
cv.notify_all();
wait( 120) ;
i = 1;
std::cerr << "Notifying again...\n";
cv.notify_all();
}
示例6: ThreadMain
void ThreadMain(ComPtr<ISwapChainPanel> swapChainPanel)
{
auto lock = GetLock();
m_dispatcher = CreateCoreDispatcher(swapChainPanel.Get());
swapChainPanel.Reset(); // we only needed this to create the dispatcher
m_conditionVariable.notify_all();
lock.unlock();
m_client->OnGameLoopStarting();
lock.lock();
m_started = true;
m_conditionVariable.notify_all();
for (;;)
{
m_conditionVariable.wait(lock, [=] { return m_shutdownRequested || !m_pendingActions.empty() || m_startDispatcher; });
if (m_shutdownRequested)
break;
if (!m_pendingActions.empty())
{
std::vector<ComPtr<AnimatedControlAsyncAction>> actions;
std::swap(actions, m_pendingActions);
lock.unlock();
RunActions(std::move(actions));
lock.lock();
}
else if (m_startDispatcher)
{
m_dispatcherStarted = true;
m_conditionVariable.notify_all();
lock.unlock();
ThrowIfFailed(m_dispatcher->ProcessEvents(CoreProcessEventsOption_ProcessUntilQuit));
lock.lock();
m_dispatcherStarted = false;
m_conditionVariable.notify_all();
}
}
// Cancel any remaining actions
CancelActions(lock);
lock.unlock();
m_client->OnGameLoopStopped();
// falling out of ThreadMain will cause ThreadCompleted to be called,
// which will mark the thread as shutdown.
}
示例7: signals
void signals()
{
std::this_thread::sleep_for(std::chrono::seconds(1));
std::cerr << "Notifying...\n";
cv.notify_all();
std::this_thread::sleep_for(std::chrono::seconds(1));
std::unique_lock<std::mutex> lk(cv_m);
i = 1;
std::cerr << "Notifying again...\n";
cv.notify_all();
}
示例8: write
/** Try to write a value to the pipe
\param[in] value is what we want to write
\param[in] blocking specify if the call wait for the operation
to succeed
\return true on success
\todo provide a && version
*/
bool write(const T &value, bool blocking = false) {
// Lock the pipe to avoid being disturbed
std::unique_lock<std::mutex> ul { cb_mutex };
TRISYCL_DUMP_T("Write pipe full = " << full()
<< " value = " << value);
if (blocking)
/* If in blocking mode, wait for the not full condition, that
may be changed when a read is done */
read_done.wait(ul, [&] { return !full(); });
else if (full())
return false;
cb.push_back(value);
TRISYCL_DUMP_T("Write pipe front = " << cb.front()
<< " back = " << cb.back()
<< " cb.begin() = " << (void *)&*cb.begin()
<< " cb.size() = " << cb.size()
<< " cb.end() = " << (void *)&*cb.end()
<< " reserved_for_reading() = " << reserved_for_reading()
<< " reserved_for_writing() = " << reserved_for_writing());
// Notify the clients waiting to read something from the pipe
write_done.notify_all();
return true;
}
示例9: do_send
// work_queue work items is are automatically dequeued and called by proton
// This function is called because it was queued by send()
void do_send(const proton::message& m) {
sender_.send(m);
std::lock_guard<std::mutex> l(lock_);
--queued_; // work item was consumed from the work_queue
credit_ = sender_.credit(); // update credit
sender_ready_.notify_all(); // Notify senders we have space on queue
}
示例10: pop
void pop()
{
internal.pop();
if (empty())
is_empty.notify_all();
}
示例11: Save
void Save(Data &&data)
{
std::unique_lock<std::mutex> lock(m_queueGuard);
m_queue.emplace();
m_queue.back().swap(data);
m_condition.notify_all();
}
示例12: onAdminQueryMessage
virtual void onAdminQueryMessage(const std::string& message)
{
std::unique_lock<std::mutex> lock(_messageReceivedMutex);
_messageReceivedCV.notify_all();
_messageReceived = message;
Log::info("UnitAdmin:: onAdminQueryMessage: " + message);
}
示例13: lock
// Called when the read op terminates
void
on_read_done()
{
std::lock_guard<std::mutex> lock(m0_);
b0_ = true;
cv0_.notify_all();
}
示例14: lock
void process(int thread_index)
{
(void)(thread_index); //currently unused, but maybe useful on debugging.
for( ; ; ) {
if(is_terminated()) {
break;
}
task_ptr_t task = task_queue_.dequeue();
bool should_notify = false;
task->run();
{
task_count_lock_t lock(task_count_mutex_);
--task_count_;
if(is_waiting() && task_count_ == 0) {
should_notify = true;
}
}
if(should_notify) {
c_task_.notify_all();
}
}
}
示例15: open
inline void open()
{
std::lock_guard<std::mutex> lock(this->mutex);
closed = false;
cond.notify_all();
}