本文整理汇总了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;
}
示例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();
}
示例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));
}
示例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();
}
示例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();
}
}
示例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();
}
示例7: l
~FrozenCleanupCheck()
{
if (should_freeze) {
std::unique_lock<std::mutex> l(m);
nFrozen = 1;
cv.notify_one();
cv.wait(l, []{ return nFrozen == 0;});
}
}
示例8: lock
~ManagerImp () override
{
{
std::lock_guard<std::mutex> lock(mutex_);
stop_ = true;
cond_.notify_one();
}
thread_.join();
}
示例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;});
}
}
示例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();
}
}
示例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();
}
示例12: one_done
void one_done()
{
std::unique_lock<std::mutex> g(mutex_);
++current_;
if ( current_ == required_ )
{
cv_.notify_one();
}
}
示例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));
}
}
示例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;
}
示例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();
}
}