本文整理汇总了C++中boost::condition_variable::notify_all方法的典型用法代码示例。如果您正苦于以下问题:C++ condition_variable::notify_all方法的具体用法?C++ condition_variable::notify_all怎么用?C++ condition_variable::notify_all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::condition_variable
的用法示例。
在下文中一共展示了condition_variable::notify_all方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Run
void Run(const Reciever &reciever)
{
boost::mutex mutex;
boost::unique_lock<boost::mutex> lock(mutex);
progress = 0.5f;
started.notify_all();
end.wait(lock);
progress = 1;
ended.notify_all();
}
示例2: mark_for_deletion
/**
* Try mark the file for deletion. Only few file states permit this operation to happen.
*
* @return true if file was marked for deletion
* No one should reference this file since it is marked for deletion
*/
inline bool mark_for_deletion(){
boost::mutex::scoped_lock lock(m_state_changed_mux);
bool marked = false;
LOG (INFO) << "Managed file OTO \"" << fqp() << "\" with state \"" << state() << "\" is requested for deletion." <<
"subscribers # = " << m_subscribers.load(std::memory_order_acquire) << "\n";
// check all states that allow to mark the file for deletion:
State expected = State::FILE_IS_IDLE;
// look for "idle marker"
marked = m_state.compare_exchange_strong(expected, State::FILE_IS_MARKED_FOR_DELETION);
if(marked){
// wait for all detaching clients to finish:
boost::unique_lock<boost::mutex> detaching_lock(m_detaching_mux_guard);
m_detaching_condition.wait(detaching_lock, [&]{ return (m_detaching_clients.size() == 0); });
detaching_lock.unlock();
// go ahead, no detaching clients are in progress more
m_state_changed_condition.notify_all();
LOG (INFO) << "Managed file OTO \"" << fqp() << "\" with state \"" << state() <<
"\" is successfully marked for deletion." << "\n";
if(m_subscribers.load(std::memory_order_acquire) == 0)
return true;
return false;
}
expected = State::FILE_IS_FORBIDDEN;
marked = m_state.compare_exchange_strong(expected, State::FILE_IS_MARKED_FOR_DELETION);
if(marked){
m_state_changed_condition.notify_all();
LOG (INFO) << "Managed file OTO \"" << fqp() << "\" with state \"" << state() <<
"\" is successfully marked for deletion." << "\n";
if(m_subscribers.load(std::memory_order_acquire) == 0)
return true;
return false;
}
expected = State::FILE_IS_AMORPHOUS;
marked = m_state.compare_exchange_strong(expected, State::FILE_IS_MARKED_FOR_DELETION);
m_state_changed_condition.notify_all();
marked = (marked && (m_subscribers.load(std::memory_order_acquire) == 0));
std::string marked_str = marked ? "successfully" : "NOT";
LOG (INFO) << "Managed file OTO \"" << fqp() << "\" with state \"" << state() <<
"\" is " << marked_str << " marked for deletion." << "\n";
return marked;
}
示例3: Reschedule
/**
* Reschedules this timer.
*
* @param next The time when this timer should be called again. Use -1 to let
* the timer figure out a suitable time based on the interval.
*/
void Timer::Reschedule(double next)
{
ASSERT(!OwnsLock());
boost::mutex::scoped_lock lock(l_Mutex);
if (next < 0) {
/* Don't schedule the next call if this is not a periodic timer. */
if (m_Interval <= 0)
return;
next = Utility::GetTime() + m_Interval;
}
m_Next = next;
if (m_Started) {
/* Remove and re-add the timer to update the index. */
l_Timers.erase(GetSelf());
l_Timers.insert(GetSelf());
/* Notify the worker that we've rescheduled a timer. */
l_CV.notify_all();
}
}
示例4: AutocompleteScriptCompletionHandler
void ConsoleCommand::AutocompleteScriptCompletionHandler(boost::mutex& mutex, boost::condition_variable& cv,
bool& ready, const boost::exception_ptr& eptr, const Array::Ptr& result, Array::Ptr& resultOut)
{
if (eptr) {
try {
boost::rethrow_exception(eptr);
} catch (const std::exception& ex) {
Log(LogCritical, "ConsoleCommand")
<< "HTTP query failed: " << ex.what();
#ifdef HAVE_EDITLINE
/* Ensures that the terminal state is resetted */
rl_deprep_terminal();
#endif /* HAVE_EDITLINE */
Application::Exit(EXIT_FAILURE);
}
}
resultOut = result;
{
boost::mutex::scoped_lock lock(mutex);
ready = true;
cv.notify_all();
}
}
示例5: InternalReschedule
/**
* Reschedules this timer.
*
* @param completed Whether the timer has just completed its callback.
* @param next The time when this timer should be called again. Use -1 to let
* the timer figure out a suitable time based on the interval.
*/
void Timer::InternalReschedule(bool completed, double next)
{
ASSERT(!OwnsLock());
boost::mutex::scoped_lock lock(l_TimerMutex);
if (completed)
m_Running = false;
if (next < 0) {
/* Don't schedule the next call if this is not a periodic timer. */
if (m_Interval <= 0)
return;
next = Utility::GetTime() + m_Interval;
}
m_Next = next;
if (m_Started && !m_Running) {
/* Remove and re-add the timer to update the index. */
l_Timers.erase(this);
l_Timers.insert(this);
/* Notify the worker that we've rescheduled a timer. */
l_TimerCV.notify_all();
}
}
示例6: start
void start() {
runningState_mutex->lock();
*runningState = RUNNING;
runningState_mutex->unlock();
cv->notify_all();
}
示例7: pause
void pause() {
runningState_mutex->lock();
*runningState = PAUSED;
runningState_mutex->unlock();
cv->notify_all();
}
示例8: main
int main(int argc, char **argv) {
ros::init(argc, argv, "recognizer");
ros::NodeHandle n("~");
n.param("configuration", JULIUS_CONFIGURATION, string(""));
n.param("debug", JULIUS_DEBUG, (bool)FALSE);
if (JULIUS_CONFIGURATION.empty()) {
ROS_ERROR("No Julius configuration file provided");
return -1;
}
boost::thread julius_thread(recognize);
commands = n.advertise<std_msgs::String>(std::string("output"), 1000);
ros::ServiceServer start_service = n.advertiseService<std_srvs::Empty::Request, std_srvs::Empty::Response>(ros::this_node::getName() + std::string("/start"), start_service_callback);
ros::ServiceServer stop_service = n.advertiseService<std_srvs::Empty::Request, std_srvs::Empty::Response>(ros::this_node::getName() + std::string("/stop"), stop_service_callback);
n.createTimer(ros::Duration(5), watchdog);
ros::spin();
if (recog) j_request_terminate(recog);
pause_variable.notify_all();
//julius_thread.join();
return 0;
}
示例9: cleanup
void MANAGER :: cleanup (void)
{
LogString saved_context;
LOGGER_PUSH_NDCTAG (LOGGER_TAG_MANAGER);
LOG4CXX_INFO (_logger, "Cleaning up by joining all the workers.");
if (_nWorkers <= 0)
{
LOG4CXX_INFO (_logger, "There are no workers in the pool. Hence no cleanup is required. Returning...");
LOGGER_POP_NDCTAG;
return;
}
/* notify all workers about whole_job_completed */
{
boost::lock_guard<boost::mutex> lock(mut);
command_from_manager = 1;
whole_job_completed = 1;
free_workers_mutex.lock();
LOG4CXX_DEBUG (_logger, "sending whole_job_completed notification to all. Currently free_workers = " << free_workers);
free_workers_mutex.unlock();
cond.notify_all ();
}
free_workers_mutex.lock();
LOG4CXX_INFO (_logger, "joining all. Currently free_workers = " << free_workers);
free_workers_mutex.unlock();
join_all ();
free_workers_mutex.lock();
LOG4CXX_INFO (_logger, "joined all. Currently free_workers = " << free_workers);
free_workers_mutex.unlock();
LOGGER_POP_NDCTAG;
}
示例10: datagen_thread_loop
/* threat functions*/
void datagen_thread_loop(void)
{
ostringstream testline;
/* create testdata*/
int jj=0;
for(int ii=0; ii < 8*8-1; ii++) //64 = 63 chars + end line
{
if(++jj > 9) jj = 0;
testline << jj;
}
testline << "\n";
jj=0;
while(record_thread_running && jj < NUM_LINES)
{
#if !defined(WITH_BOOST_TIME)
clock_gettime(CLOCK_MONOTONIC, &ts_beg); // http://linux.die.net/man/3/clock_gettime
#else
start_time = boost::posix_time::microsec_clock::local_time();
#endif
// ********************************* //
*active_buffer += testline.str().c_str();
if(4*1024 < active_buffer->length()) //write 4 kbyte blocks
{
record_trigger.notify_all();
}
// ********************************* //
#if !defined(WITH_BOOST_TIME)
clock_gettime(CLOCK_MONOTONIC, &ts_end);
v_fTime_s.push_back(ts_end.tv_sec);
v_fTime_us.push_back(ts_end.tv_nsec/1e+3);
v_fDifftime.push_back((ts_end.tv_sec - ts_beg.tv_sec) + (ts_end.tv_nsec - ts_beg.tv_nsec) / 1e9);
f_DT_s = (ts_end.tv_sec - ts_beg.tv_sec) + (ts_end.tv_nsec - ts_beg.tv_nsec) / 1e9;
#else
stop_time = boost::posix_time::microsec_clock::local_time();
time_duration = (stop_time - start_time);
v_fTime_s.push_back( (stop_time-boost::posix_time::from_time_t(0)).total_seconds() );
v_fTime_us.push_back( (stop_time-boost::posix_time::from_time_t(0)).fractional_seconds() );
v_fDifftime.push_back( time_duration.total_seconds()+ time_duration.fractional_seconds()/ 1e6);
f_DT_s = (time_duration.total_seconds()+ time_duration.fractional_seconds()/ 1e6);
#endif
#if defined(DEBUG)
if(0.5 < 1.e+3*f_DT_s) // log only values above 0.5 ms
{
cout << "Line " << jj << " of " << NUM_LINES << ":"
<< "\t" << v_fTime_s.back() << "." << v_fTime_us.back() << "s: "
<< "\tdT: " << fixed << 1.e+3*f_DT_s << " ms"
<< endl;
}
#endif
boost::this_thread::sleep(boost::posix_time::microseconds(4*1e+6*f_DT_s)); //about 50% CPU load
jj++;
}//while
datagen_done = true;
}
示例11: step
void step() {
if(getRunningState() != RUNNING) {
boost::lock_guard<boost::mutex> lock2(*esc64_mutex);
esc64->step();
}
cv->notify_all();
}
示例12: push
// for message queue
void push(T data)
{
boost::mutex::scoped_lock lockHandle(mutexHandle);
queueHandle.push(data);
lockHandle.unlock();
condFlag.notify_all();
}
示例13: MessageHandler
void MessageHandler(CoinNodeSocket* pNodeSocket, const CoinNodeMessage& message)
{
if (string(message.getCommand()) == "version") {
cout << message.toIndentedString() << endl;
boost::unique_lock<boost::mutex> lock(mutex);
bGotVersion = true;
gotVersion.notify_all();
}
}
示例14: wait_and_push
// for data queue
void wait_and_push(T data)
{
boost::mutex::scoped_lock lockHandle(mutexHandle);
condFlag.wait(lockHandle, isFull(&queueHandle, sizeMax));
queueHandle.push(data);
lockHandle.unlock();
condFlag.notify_all();
}
示例15: stop
void stop()
{
io_service_.stop();
{
boost::lock_guard<boost::mutex> lock(mutex_);
terminated_ = true;
}
condition_.notify_all();
}