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


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

本文整理汇总了C++中std::condition_variable::notify_one方法的典型用法代码示例。如果您正苦于以下问题:C++ condition_variable::notify_one方法的具体用法?C++ condition_variable::notify_one怎么用?C++ condition_variable::notify_one使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在std::condition_variable的用法示例。


在下文中一共展示了condition_variable::notify_one方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: lk

 std::shared_ptr<T> wait_and_pop()
 {
     std::unique_lock<std::mutex> lk(mut);
     data_cond.wait(lk,[this]{return !data_queue.empty();});
     std::shared_ptr<T> res(std::make_shared<T>(data_queue.front()));
     data_queue.pop();
     empty_cond.notify_one();
     return res;
 }
开发者ID:Percona-Lab,项目名称:MetricBench,代码行数:9,代码来源:tsqueue.hpp

示例2: notify

static void notify(TestData &test,TestResult result)
{
    {
        std::lock_guard<std::mutex>  lk(m_mtx);
        --m_running_tests;
        test.result = result;
    }
    m_cndvar.notify_one();
}
开发者ID:sveljko,项目名称:c-core,代码行数:9,代码来源:pubnub_fntest_runner.cpp

示例3: provider

void provider(int val){
	//push different valus(val til val+5 with timeouts of val milliseconds into the queue)
	for (int i = 0; i < 6; ++i){
		std::lock_guard<std::mutex> lg(queueMutex);
		queue.push(val + 1);
	}//release lock
	queueConVar.notify_one();
	std::this_thread::sleep_for(std::chrono::milliseconds(val));
}
开发者ID:catchSora,项目名称:exercises,代码行数:9,代码来源:condiVarQueue.cpp

示例4: releaseCompiler

void CompilerPool::releaseCompiler(size_t id, ExternCompiler* ptr) {
  std::unique_lock<std::mutex> l(m_compilerLock);

  m_compilers[id].store(ptr, std::memory_order_relaxed);
  m_freeCount += 1;

  l.unlock();
  m_compilerCv.notify_one();
}
开发者ID:fredemmott,项目名称:hhvm,代码行数:9,代码来源:extern-compiler.cpp

示例5: signals

void signals()
{
    std::this_thread::sleep_for(std::chrono::seconds(1));
    std::cout << "Notifying falsely...\n";
    cv.notify_one();
   //Most probably, the waiting thread is awaken unnecessarily.
 
    std::unique_lock<std::mutex> lk(cv_m);
    i = 1;
    while (!done) 
    {
        std::cout << "Notifying true change...\n";
        lk.unlock(); //It is a good idea unlock before notifying.
        cv.notify_one();
        std::this_thread::sleep_for(std::chrono::seconds(1));
        lk.lock();
    }
}
开发者ID:CCJY,项目名称:coliru,代码行数:18,代码来源:main.cpp

示例6: add

 void add(int id, int data) {
     std::unique_lock<std::mutex> l(lock_);
     notFull_.wait(l, [this]() { return size_ < capacity_; });
     buffer_[rear_] = data;
     rear_ = (rear_ + 1) % capacity_;
     ++size_;
     std::cout << "Produced " << id << " produced " << data << std::endl;
     notEmpty_.notify_one();
 }
开发者ID:new-projects,项目名称:c11,代码行数:9,代码来源:ProducerConsumer.cpp

示例7: l

 ~FrozenCleanupCheck()
 {
     if (should_freeze) {
         std::unique_lock<std::mutex> l(m);
         nFrozen = 1;
         cv.notify_one();
         cv.wait(l, []{ return nFrozen == 0;});
     }
 }
开发者ID:21E14,项目名称:bitcoin,代码行数:9,代码来源:checkqueue_tests.cpp

示例8: lock

 ~ManagerImp () override
 {
     {
         std::lock_guard<std::mutex> lock(mutex_);
         stop_ = true;
         cond_.notify_one();
     }
     thread_.join();
 }
开发者ID:dreamsxin,项目名称:rippled,代码行数:9,代码来源:ResourceManager.cpp

示例9: l

 ~FrozenCleanupCheck()
 {
     if (should_freeze) {
         std::unique_lock<std::mutex> l(m);
         nFrozen.store(1, std::memory_order_relaxed);
         cv.notify_one();
         cv.wait(l, []{ return nFrozen.load(std::memory_order_relaxed) == 0;});
     }
 }
开发者ID:jally76,项目名称:bitcoin,代码行数:9,代码来源:checkqueue_tests.cpp

示例10: pong

void pong()
{  
    std::unique_lock<std::mutex> lock(m);
    pong_cond.notify_one();
    
    while(!done)
    {
        ping_cond.wait(lock);
        
        if(need_to_pong)
        {
            std::cout << "Pong!\n";
            need_to_pong = false;
        }
        
        pong_cond.notify_one();
    }
}
开发者ID:CCJY,项目名称:coliru,代码行数:18,代码来源:main.cpp

示例11: ComeToWork

 void ComeToWork()
 {
     std::cout << "Hey security, please open the door!\n";
     g_Bell.notify_one();
     std::mutex mutex;
     mutex.lock();
     g_Door.wait(mutex);
     mutex.unlock();
 }
开发者ID:lmikheevskaya,项目名称:LevelUP_Junior,代码行数:9,代码来源:condition_variable.cpp

示例12: one_done

 void one_done()
 {
     std::unique_lock<std::mutex> g(mutex_);
     ++current_;
     if ( current_ == required_ )
     {
         cv_.notify_one();
     }
 }
开发者ID:Nuzhny007,项目名称:znn-release,代码行数:9,代码来源:waiter.hpp

示例13: eat

void eat(int* part) {
  while (!stopped) {
    std::unique_lock<std::mutex> lock(mutex);
    BIG_PIE -= 100;
    *part += 100;
    cond.notify_one();
    cond.wait_for(lock, std::chrono::milliseconds(100));
  }
}
开发者ID:duplyakin,项目名称:CppCourse,代码行数:9,代码来源:condition_variable_1_1.cpp

示例14: get

 int get(int id) {
     std::unique_lock<std::mutex> l(lock_);
     notEmpty_.wait(l, [this]() { return size_ > 0; });
     int data = buffer_[front_];
     front_ = (front_ + 1) % capacity_;
     --size_;
     std::cout << "Consumer " << id << " fetched " << data << std::endl;
     notFull_.notify_one();
     return data;
 }
开发者ID:new-projects,项目名称:c11,代码行数:10,代码来源:ProducerConsumer.cpp

示例15: print

void print(int max, bool isEven)
{
    for (int i = isEven ? 0 : 1; i < max; i += 2) {
        std::unique_lock<std::mutex> lock(mtx);
        cv.wait(lock);
        std::cout << i + 1 << std::endl;
        lock.unlock();
        cv.notify_one();
    }
}
开发者ID:kyliau,项目名称:playground,代码行数:10,代码来源:print_100_two_threads.cpp


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