本文整理汇总了C++中thread::Condition::wait方法的典型用法代码示例。如果您正苦于以下问题:C++ Condition::wait方法的具体用法?C++ Condition::wait怎么用?C++ Condition::wait使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类thread::Condition
的用法示例。
在下文中一共展示了Condition::wait方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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_++;
}
}
示例2: 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";
}
}
示例3: 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_++;
}
示例4: wait_to_run
void wait_to_run() {
pending_threads_--;
waiting_to_stop_.signal();
while(should_stop_) {
waiting_to_run_.wait(mutex_);
}
pending_threads_++;
}
示例5: 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_);
}
}
示例6: 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";
}
}