当前位置: 首页>>代码示例>>C++>>正文


C++ condition_variable::notify_all方法代码示例

本文整理汇总了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();
    }
开发者ID:Louisvh,项目名称:openPSTD,代码行数:11,代码来源:LongOperationRunner-test.cpp

示例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;
	   }
开发者ID:ImpalaToGo,项目名称:ImpalaToGo,代码行数:57,代码来源:managed-file.hpp

示例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();
	}
}
开发者ID:CSRedRat,项目名称:icinga2,代码行数:31,代码来源:timer.cpp

示例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();
	}
}
开发者ID:dupondje,项目名称:icinga2,代码行数:27,代码来源:consolecommand.cpp

示例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();
	}
}
开发者ID:andrewmeyer,项目名称:icinga2,代码行数:35,代码来源:timer.cpp

示例6: start

	void start() {
		runningState_mutex->lock();
		*runningState = RUNNING;
		runningState_mutex->unlock();

		cv->notify_all();
	}
开发者ID:theepot,项目名称:esc64,代码行数:7,代码来源:main.cpp

示例7: pause

	void pause() {
		runningState_mutex->lock();
		*runningState = PAUSED;
		runningState_mutex->unlock();

		cv->notify_all();
	}
开发者ID:theepot,项目名称:esc64,代码行数:7,代码来源:main.cpp

示例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;
}
开发者ID:pr3mar,项目名称:ROS,代码行数:33,代码来源:recognizer.cpp

示例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;
}
开发者ID:tshead,项目名称:scidb-osx-12.3-snow-leopard,代码行数:34,代码来源:manager.cpp

示例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;
    }
开发者ID:Tri-o-copter,项目名称:Brainware,代码行数:60,代码来源:logging_thread_tests.cpp

示例11: step

	void step() {
		if(getRunningState() != RUNNING) {
			boost::lock_guard<boost::mutex> lock2(*esc64_mutex);

			esc64->step();
		}
		cv->notify_all();
	}
开发者ID:theepot,项目名称:esc64,代码行数:8,代码来源:main.cpp

示例12: push

    // for message queue
    void push(T data)
    {
        boost::mutex::scoped_lock     lockHandle(mutexHandle);

        queueHandle.push(data);
        lockHandle.unlock();
        condFlag.notify_all();
    }
开发者ID:hvthaibk,项目名称:ccrunch,代码行数:9,代码来源:cThreadBoost.hpp

示例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();
    }
}
开发者ID:AndreV84,项目名称:mSIGNA,代码行数:9,代码来源:ping.cpp

示例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();
    }
开发者ID:hvthaibk,项目名称:ccrunch,代码行数:10,代码来源:cThreadBoost.hpp

示例15: stop

 void stop()
 {
     io_service_.stop();
     {
         boost::lock_guard<boost::mutex> lock(mutex_);
         terminated_ = true;
     }
     condition_.notify_all();
 }
开发者ID:hamazy,项目名称:shiritori,代码行数:9,代码来源:server.hpp


注:本文中的boost::condition_variable::notify_all方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。