本文整理汇总了C++中thread::Condition类的典型用法代码示例。如果您正苦于以下问题:C++ Condition类的具体用法?C++ Condition怎么用?C++ Condition使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Condition类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: reinit
// Called after a fork(), when we know we're alone again, to get
// everything back in the proper order.
void reinit() {
mutex_.init();
waiting_to_stop_.init();
waiting_to_run_.init();
pending_threads_ = 1;
should_stop_ = false;
}
示例2: wait_to_run
void wait_to_run() {
pending_threads_--;
waiting_to_stop_.signal();
while(should_stop_) {
waiting_to_run_.wait(mutex_);
}
pending_threads_++;
}
示例3: become_dependent
void become_dependent(THREAD) {
thread::Mutex::LockGuard guard(mutex_);
switch(state->run_state()) {
case ManagedThread::eAlone:
// Running alone, ignore.
return;
case ManagedThread::eRunning:
// Ignore this, a running thread is already dependent.
return;
case ManagedThread::eSuspended:
// Again, bad, don't allow this.
rubinius::bug("Trying to make a suspended thread dependent");
break;
case ManagedThread::eIndependent:
// If the GC is running, wait here...
while(should_stop_) {
waiting_to_run_.wait(mutex_);
}
// Ok, we're running again.
state->run_state_ = ManagedThread::eRunning;
pending_threads_++;
}
}
示例4: wait_til_alone
void wait_til_alone(THREAD) {
thread::Mutex::LockGuard guard(mutex_);
should_stop_ = true;
if(cDebugThreading) {
std::cerr << "[" << VM::current() << " WORLD waiting until alone]\n";
}
if(state->run_state_ != ManagedThread::eRunning) {
rubinius::bug("A non-running thread is trying to wait till alone");
}
// For ourself..
pending_threads_--;
timer::Running<> timer(time_waiting_);
while(pending_threads_ > 0) {
if(cDebugThreading) {
std::cerr << "[" << VM::current() << " WORLD waiting on condvar: "
<< pending_threads_ << "]\n";
}
waiting_to_stop_.wait(mutex_);
}
state->run_state_ = ManagedThread::eAlone;
if(cDebugThreading) {
std::cerr << "[" << VM::current() << " WORLD o/~ I think we're alone now.. o/~]\n";
}
}
示例5: unpark
void unpark() {
thread::Mutex::LockGuard lg(mutex_);
if(!sleeping_) return;
wake_ = true;
cond_.signal();
}
示例6: become_dependent
void become_dependent() {
thread::Mutex::LockGuard guard(mutex_);
// If the GC is running, wait here...
while(should_stop_) {
waiting_to_run_.wait(mutex_);
}
pending_threads_++;
}
示例7: wake_all_waiters
void wake_all_waiters() {
thread::Mutex::LockGuard guard(mutex_);
should_stop_ = false;
// For ourself..
pending_threads_++;
waiting_to_run_.broadcast();
}
示例8: wait_til_alone
void wait_til_alone() {
thread::Mutex::LockGuard guard(mutex_);
should_stop_ = true;
// For ourself..
pending_threads_--;
timer::Running timer(time_waiting_);
while(pending_threads_ > 0) {
waiting_to_stop_.wait(mutex_);
}
}
示例9: wait_to_run
void wait_to_run(THREAD) {
if(cDebugThreading) {
std::cerr << "[" << VM::current() << " WORLD stopping, waiting to be restarted]\n";
}
if(state->run_state_ != ManagedThread::eRunning) {
rubinius::bug("Suspending a non running thread!");
}
state->run_state_ = ManagedThread::eSuspended;
pending_threads_--;
waiting_to_stop_.signal();
while(should_stop_) {
waiting_to_run_.wait(mutex_);
}
pending_threads_++;
state->run_state_ = ManagedThread::eRunning;
if(cDebugThreading) {
std::cerr << "[" << VM::current() << " WORLD restarted]\n";
}
}
示例10: wake_all_waiters
void wake_all_waiters(THREAD) {
thread::Mutex::LockGuard guard(mutex_);
should_stop_ = false;
if(cDebugThreading) {
std::cerr << "[" << VM::current() << " WORLD waking all threads]\n";
}
if(state->run_state_ != ManagedThread::eAlone) {
rubinius::bug("A non-alone thread is trying to wake all");
}
// For ourself..
pending_threads_++;
waiting_to_run_.broadcast();
state->run_state_ = ManagedThread::eRunning;
}