当前位置: 首页>>代码示例>>C++>>正文


C++ condition_variable::notify_all方法代码示例

本文整理汇总了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; });
            }
        }
    }
开发者ID:UWB-Biocomputing,项目名称:BrainGrid,代码行数:29,代码来源:Barrier.hpp

示例2: writeUnlock

		/**
		 * @brief Unlock on writing
		 */
		void writeUnlock()
		{
			writing_ = false;
			
			read_cv_.notify_all();
			write_cv_.notify_all();
		};
开发者ID:samchon,项目名称:framework,代码行数:10,代码来源:RWMutex.hpp

示例3: halt

 void halt() {
     {
         std::lock_guard<std::mutex> lk(mutex);
         if (!running) return;
         running = false;
     }
     tasks_updated.notify_all();
     modified.notify_all();
 }
开发者ID:OpsRaven,项目名称:SenecaOOP345-attic,代码行数:9,代码来源:thread-schedule.cpp

示例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();
}
开发者ID:WhiZTiM,项目名称:coliru,代码行数:10,代码来源:main.cpp

示例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();
}
开发者ID:GDXN,项目名称:test,代码行数:10,代码来源:threadcondwait.cpp

示例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.
    }
开发者ID:jiatingxiu,项目名称:Win2D,代码行数:54,代码来源:GameLoopThread.cpp

示例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();
}
开发者ID:xiongyang,项目名称:MyLibiary,代码行数:12,代码来源:TestCondiftion.cpp

示例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;
  }
开发者ID:loic-yvonnet,项目名称:triSYCL,代码行数:36,代码来源:pipe.hpp

示例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
 }
开发者ID:apache,项目名称:qpid-proton,代码行数:9,代码来源:multithreaded_client_flow_control.cpp

示例10: pop

	void pop()
	{
		internal.pop();
		if (empty())
			is_empty.notify_all();

	}
开发者ID:CCJY,项目名称:coliru,代码行数:7,代码来源:main.cpp

示例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();
	}
开发者ID:heimdallr,项目名称:home_compa_dev,代码行数:7,代码来源:ResultSaver.cpp

示例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);
 }
开发者ID:BJFletcher94,项目名称:online,代码行数:7,代码来源:UnitAdmin.cpp

示例13: lock

 // Called when the read op terminates
 void
 on_read_done()
 {
     std::lock_guard<std::mutex> lock(m0_);
     b0_ = true;
     cv0_.notify_all();
 }
开发者ID:yunsite,项目名称:rippled,代码行数:8,代码来源:WSClient.cpp

示例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();
			}
        }
	}
开发者ID:bratao,项目名称:CRFSegmenter,代码行数:29,代码来源:task_queue.hpp

示例15: open

    inline void open()
    {
        std::lock_guard<std::mutex> lock(this->mutex);

        closed = false;
        cond.notify_all();
    }
开发者ID:rideliner,项目名称:concurrency,代码行数:7,代码来源:gate.hpp


注:本文中的std::condition_variable::notify_all方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。