本文整理汇总了C++中std::condition_variable_any::notify_one方法的典型用法代码示例。如果您正苦于以下问题:C++ condition_variable_any::notify_one方法的具体用法?C++ condition_variable_any::notify_one怎么用?C++ condition_variable_any::notify_one使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::condition_variable_any
的用法示例。
在下文中一共展示了condition_variable_any::notify_one方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: f
void f()
{
typedef std::chrono::system_clock Clock;
typedef std::chrono::milliseconds milliseconds;
L1 lk(m0);
assert(test2 == 0);
test1 = 1;
cv.notify_one();
Clock::time_point t0 = Clock::now();
while (test2 == 0 &&
cv.wait_for(lk, milliseconds(250)) == std::cv_status::no_timeout)
;
Clock::time_point t1 = Clock::now();
if (runs == 0)
{
assert(t1 - t0 < milliseconds(250));
assert(test2 != 0);
}
else
{
assert(t1 - t0 - milliseconds(250) < milliseconds(5));
assert(test2 == 0);
}
++runs;
}
示例2: post
void post()
{
std::lock_guard<std::mutex> lock(mutex_);
//++count_;
work_waiting = true;
condition_.notify_one();
}
示例3: _process
void _process(int id) {
std::unique_lock<std::mutex> lock(io_datas[id]->mtx);
if(io_datas[id]->empty()) {
io_datas[id]->cond.wait(lock);
/* In case that the queue is not used at the begining and it shall
* make dequeue operation failed. */
if(io_datas[id]->empty()) {
lock.unlock();
return;
}
}
IoRef io = io_datas[id]->dequeue();
lock.unlock();
auto time_beg = std::chrono::steady_clock::now();
handle_io(io->offset, io->c);
auto time_end = std::chrono::steady_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(time_end - time_beg).count();
io_counter_per_thread[id]++;
perf.consumed_time += duration;
perf.io_finished++;
prod_cond.notify_one();
}
示例4: main
int main()
{
{
L1 lk(m0);
std::thread t(f);
assert(test1 == 0);
while (test1 == 0)
cv.wait(lk);
assert(test1 != 0);
test2 = 1;
lk.unlock();
cv.notify_one();
t.join();
}
test1 = 0;
test2 = 0;
{
L1 lk(m0);
std::thread t(f);
assert(test1 == 0);
while (test1 == 0)
cv.wait(lk);
assert(test1 != 0);
lk.unlock();
t.join();
}
}
示例5: f
void f()
{
L1 lk(m0);
assert(test2 == 0);
test1 = 1;
cv.notify_one();
cv.wait(lk, Pred(test2));
assert(test2 != 0);
}
示例6: post
void Worker::post(const QueryPtr& query)
{
{
std::lock_guard<std::mutex> guard(mutex_);
assert(follower_query_ == nullptr);
follower_query_ = query;
}
cond_.notify_one();
}
示例7: addWork
/*供messagemanager调用*/
bool ThreadPool::addWork()
{
/*工作线程数加一*/
std::lock_guard<std::mutex> lck(mtx);
if(isFull())
throw Exception(ERR_BAD,"线程池已经用完,无法提供ThreadPool::addWork()调用");
freeThreadNumber--;
cond_var.notify_one();//唤醒一个线程,并从消息队列取消息处理
return true;
}
示例8: post_to_queue
void Worker::post_to_queue(const QueryPtr& query)
{
if (!working_) return;
{
std::lock_guard<std::mutex> guard(mutex_);
query_queue_.push_back(query);
}
cond_.notify_one();
}
示例9: lock
HttpClient::~HttpClient()
{
if (s_requestQueue != nullptr) {
{
std::lock_guard<std::mutex> lock(s_requestQueueMutex);
s_requestQueue->pushBack(s_requestSentinel);
}
s_SleepCondition.notify_one();
}
s_pHttpClient = nullptr;
}
示例10: stop
void Worker::stop()
{
working_ = false;
if (thread_ != nullptr)
{
cond_.notify_one();
thread_->join();
thread_.reset();
}
mysql_close(&conn_);
}
示例11: WorkHard
void WorkHard()
{
m_SectorClear = true;
std::mutex mutex;
std::unique_lock<std::mutex> lock(mutex);
while(true)
{
if(g_Bell.wait_for(lock, std::chrono::seconds(5)) == std::cv_status::timeout)
std::this_thread::sleep_for(std::chrono::seconds(10));
else
{
NotifyFellows();
g_Door.notify_one();
std::cout << "Hello Great Manager, your slaves are ready to serve you!\n" << std::endl;
}
}
}
示例12: send
//Add a get task to queue
void HttpClient::send(HttpRequest* request)
{
if (false == lazyInitThreadSemphore())
{
return;
}
if (!request)
{
return;
}
request->retain();
if (nullptr != s_requestQueue) {
s_requestQueueMutex.lock();
s_requestQueue->pushBack(request);
s_requestQueueMutex.unlock();
// Notify thread start to work
s_SleepCondition.notify_one();
}
}
示例13: f
void f()
{
typedef std::chrono::system_clock Clock;
typedef std::chrono::milliseconds milliseconds;
L1 lk(m0);
assert(test2 == 0);
test1 = 1;
cv.notify_one();
Clock::time_point t0 = Clock::now();
bool r = cv.wait_for(lk, milliseconds(250), Pred(test2));
Clock::time_point t1 = Clock::now();
if (runs == 0)
{
assert(t1 - t0 < milliseconds(250));
assert(test2 != 0);
}
else
{
assert(t1 - t0 - milliseconds(250) < milliseconds(5));
assert(test2 == 0);
}
++runs;
}
示例14: f
void f()
{
L1 lk(m0);
assert(test2 == 0);
test1 = 1;
cv.notify_one();
Clock::time_point t0 = Clock::now();
Clock::time_point t = t0 + Clock::duration(250);
while (test2 == 0 && cv.wait_until(lk, t) == std::cv_status::no_timeout)
;
Clock::time_point t1 = Clock::now();
if (runs == 0)
{
assert(t1 - t0 < Clock::duration(250));
assert(test2 != 0);
}
else
{
assert(t1 - t0 - Clock::duration(250) < Clock::duration(5));
assert(test2 == 0);
}
++runs;
}
示例15: f
void f()
{
L1 lk(m0);
assert(test2 == 0);
test1 = 1;
cv.notify_one();
Clock::time_point t0 = Clock::now();
Clock::time_point t = t0 + Clock::duration(250);
bool r = cv.wait_until(lk, t, Pred(test2));
Clock::time_point t1 = Clock::now();
if (runs == 0)
{
assert(t1 - t0 < Clock::duration(250));
assert(test2 != 0);
assert(r);
}
else
{
assert(t1 - t0 - Clock::duration(250) < Clock::duration(2));
assert(test2 == 0);
assert(!r);
}
++runs;
}