本文整理汇总了C++中hpx::lcos::local::condition_variable类的典型用法代码示例。如果您正苦于以下问题:C++ condition_variable类的具体用法?C++ condition_variable怎么用?C++ condition_variable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了condition_variable类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: wait
void wait(hpx::lcos::local::spinlock& local_mutex,
hpx::lcos::local::condition_variable& local_cond_var, bool& running)
{
bool first = true;
while (!flag)
{
// signal successful initialization
if (first)
{
{
boost::lock_guard<hpx::lcos::local::spinlock> lk(local_mutex);
running = true;
}
first = false;
local_cond_var.notify_all();
}
boost::unique_lock<hpx::lcos::local::spinlock> lk(mutex);
cond_var.wait(mutex);
}
++woken;
}
示例2: do_test
void do_test(void (this_type::*test_func)())
{
Lock lock(m);
locked=false;
done=false;
hpx::thread t(test_func,this);
try
{
{
boost::unique_lock<hpx::lcos::local::mutex> lk(done_mutex);
HPX_TEST(done_cond.wait_for(lk,boost::chrono::seconds(2),
boost::bind(&this_type::is_done,this)));
HPX_TEST(!locked);
}
lock.unlock();
t.join();
}
catch(...)
{
lock.unlock();
t.join();
throw;
}
}
示例3: receive_result
void receive_result(boost::int32_t i)
{
hpx::util::spinlock::scoped_lock l(result_mutex);
if (i > final_result)
final_result = i;
result_cv.notify_one();
}
示例4: relative_wait_until_with_predicate
void relative_wait_until_with_predicate()
{
boost::unique_lock<hpx::lcos::local::spinlock> lock(mutex);
if(cond_var.wait_for(lock,boost::posix_time::seconds(5),check_flag(flag)) && flag)
{
++woken;
}
}
示例5: wait_with_predicate
void wait_with_predicate()
{
boost::unique_lock<hpx::lcos::local::spinlock> lock(mutex);
cond_var.wait(lock,check_flag(flag));
if(flag)
{
++woken;
}
}
示例6: wait_without_predicate
void wait_without_predicate()
{
boost::unique_lock<hpx::lcos::local::spinlock> lock(mutex);
while(!flag)
{
cond_var.wait(lock);
}
++woken;
}
示例7: wait_until_with_predicate
void wait_until_with_predicate()
{
boost::system_time const timeout=boost::get_system_time()+boost::posix_time::seconds(5);
boost::unique_lock<hpx::lcos::local::spinlock> lock(mutex);
if(cond_var.wait_until(lock,timeout,check_flag(flag)) && flag)
{
++woken;
}
}
示例8: locking_thread_through_constructor
void locking_thread_through_constructor()
{
Lock lock(m,boost::chrono::milliseconds(50));
boost::lock_guard<hpx::lcos::local::mutex> lk(done_mutex);
locked=lock.owns_lock();
done=true;
done_cond.notify_one();
}
示例9: locking_thread
void locking_thread()
{
Lock lock(m,boost::defer_lock);
lock.try_lock_for(boost::chrono::milliseconds(50));
boost::lock_guard<hpx::lcos::local::mutex> lk(done_mutex);
locked=lock.owns_lock();
done=true;
done_cond.notify_one();
}
示例10: wait_until_with_predicate
void wait_until_with_predicate()
{
boost::chrono::system_clock::time_point const timeout =
boost::chrono::system_clock::now() + boost::chrono::milliseconds(5);
boost::unique_lock<hpx::lcos::local::spinlock> lock(mutex);
if(cond_var.wait_until(lock,timeout,check_flag(flag)) && flag)
{
++woken;
}
}
示例11: wait_until_without_predicate
void wait_until_without_predicate()
{
boost::system_time const timeout=boost::get_system_time()+boost::posix_time::seconds(5);
boost::unique_lock<hpx::lcos::local::spinlock> lock(mutex);
while(!flag)
{
if(cond_var.wait_until(lock,timeout) == hpx::lcos::local::cv_status::timeout)
{
return;
}
}
++woken;
}
示例12: wait_until_without_predicate
void wait_until_without_predicate()
{
boost::chrono::system_clock::time_point const timeout =
boost::chrono::system_clock::now() + boost::chrono::milliseconds(5);
boost::unique_lock<hpx::lcos::local::spinlock> lock(mutex);
while(!flag)
{
if(cond_var.wait_until(lock,timeout) == hpx::lcos::local::cv_status::timeout)
{
return;
}
}
++woken;
}
示例13: hpx_main
int hpx_main()
{
hpx::id_type here = hpx::find_here();
hpx::id_type there = here;
if (hpx::get_num_localities_sync() > 1)
{
std::vector<hpx::id_type> localities = hpx::find_remote_localities();
there = localities[0];
}
{
increment_action inc;
hpx::apply_colocated(inc, there, here, 1);
}
{
hpx::unique_future<hpx::id_type> inc_f =
hpx::components::new_<increment_server>(there);
hpx::id_type where = inc_f.get();
increment_action inc;
hpx::apply_colocated(inc, where, here, 1);
}
{
hpx::unique_future<hpx::id_type> inc_f =
hpx::components::new_<increment_server>(there);
hpx::id_type where = inc_f.get();
hpx::apply_colocated<increment_action>(where, here, 1);
}
// finalize will synchronize will all pending operations
int result = hpx::finalize();
hpx::util::spinlock::scoped_lock l(result_mutex);
result_cv.wait_for(result_mutex, boost::chrono::seconds(1),
hpx::util::bind(std::equal_to<boost::int32_t>(), boost::ref(final_result), 3));
HPX_TEST_EQ(final_result, 3);
return result;
}