• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ boost::condition_variable类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中boost::condition_variable的典型用法代码示例。如果您正苦于以下问题:C++ condition_variable类的具体用法?C++ condition_variable怎么用?C++ condition_variable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了condition_variable类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: exitThread

	/**
	 * @brief	Invia la notifica di terminazione al thread
	 */
	void exitThread() {
		mutex.lock();
		busy = true;
		active = false;
		mutex.unlock();
		condition.notify_one();
	}
开发者ID:indrimuska,项目名称:Service-Oriented-Architecture,代码行数:10,代码来源:Threads.hpp


示例2: push

	void push(T const& data) {
		{
			boost::mutex::scoped_lock lock(mutex_);
			queue_.push(data);
		}
		condition_.notify_one();
	}
开发者ID:0000-bigtree,项目名称:nscp,代码行数:7,代码来源:concurrent_queue.hpp


示例3: consumeToLog

    void consumeToLog()
    {
        while (true)
        {
            try
            {
                typename LogObject::SmartPtr logObj;
                {
                    boost::mutex::scoped_lock lock(_qMutex);

                    while (_queue.size() == 0)
                    {
                        if (_isStopping)
                        {
                            std::cout << " Stopping consumeToLog Thread. " << std::endl;
                            return;
                        }
                        _qCondVar.wait(lock);
                    }

                    // Get the entry
                    logObj = _queue.front();
                    _queue.pop();
                }
                printLogObject(logObj);
            }
            catch (const boost::thread_interrupted& err)
            {
                std::cout << " Log::consumeToLog() - Got Interrupt Signal. " << _queue.size() << std::endl;
            }
        }//while
    }
开发者ID:ankithbti,项目名称:fitiedCoreCpp,代码行数:32,代码来源:Log.hpp


示例4: log

 void log(LogLevel l, const std::string& msg)
 {
     typename StringLogObject::SmartPtr logObj(new StringLogObject(msg, l));
     boost::mutex::scoped_lock lock(_stringQMutex);
     _stringQ.push(logObj);
     _stringQCondVar.notify_one();
 }
开发者ID:ankithbti,项目名称:fitiedCoreCpp,代码行数:7,代码来源:Log.hpp


示例5: 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


示例6: operator

 void operator()()
 {
     boost::mutex::scoped_lock lk(mut);
     while(!done)
     {
         cond.wait(lk);
     }
 }
开发者ID:Alexander--,项目名称:Wesnoth-1.8-for-Android,代码行数:8,代码来源:test_thread.cpp


示例7: wait

 void wait()
 {
     boost::mutex::scoped_lock l(m);
     while(!flag)
     {
         cond.wait(l);
     }
 }
开发者ID:Alexander--,项目名称:Wesnoth-1.8-for-Android,代码行数:8,代码来源:test_generic_locks.cpp


示例8: wait

 void wait()
 {
     boost::unique_lock<boost::mutex> l(m);
     while(!flag)
     {
         cond.wait(l);
     }
 }
开发者ID:BackupTheBerlios,项目名称:airdc-svn,代码行数:8,代码来源:test_generic_locks.cpp


示例9: Start

	 void Start(CThreadUnit** pTasks, int countTasks)
	 {
        {
            boost::lock_guard<boost::mutex> lock(m_Mut);
            m_bDataReady=true;
        }
        m_Cond.notify_one();
	 }
开发者ID:phyosithu,项目名称:osmpbf2sqlite,代码行数:8,代码来源:ThreadManager.cpp


示例10: execute

	//Entry point for pool threads.
	void execute()
	{
		while( true )
		{
			//Wait on condition variable while the task is empty and the pool is
			//still running.
			boost::unique_lock< boost::mutex > lock( mutex_ );
			while( tasks_.empty() && !stop_ )
			{
                cv_task_.wait( lock );
			}

			// Copy task locally and remove from the queue. This is done within
			// its own scope so that the task object is destructed immediately
			// after running the task. This is useful in the event that the function
			// contains shared_ptr arguments bound via bind.
			if( !tasks_.empty() )
			{
				++busy_;
				boost::function< void() > task = tasks_.front();
				tasks_.pop();

				lock.unlock();

				//Run the task.
				try
				{
					task();
				}
				catch( const std::exception& )
				{
					//Suppress all exceptions
				}

				// Task has finished, so increment count of available threads
				lock.lock();
				++processed_;
				++available_;
				--busy_;
				cv_finished_.notify_one();
			}
			else if( stop_ ) {
				break;
			}
        }
    }
开发者ID:oim5nu,项目名称:Programming-Resource,代码行数:47,代码来源:threadpool.hpp


示例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: wait_and_pop

 void wait_and_pop ( Data& value )
 {
    boost::mutex::scoped_lock lock ( _mutex ) ;
    while ( _queue.empty () )
       _cond.wait ( lock ) ;
    value = _queue.front () ;
    _queue.pop () ;
 }
开发者ID:2015520,项目名称:SequoiaDB,代码行数:8,代码来源:ossQueue.hpp


示例13: waitAndGetFrontElement

	unsigned long long waitAndGetFrontElement(T* &pFrontData) {
		boost::mutex::scoped_lock lock(_mutex);
		while (_queue.empty()) {
			_conditionVar.wait(lock);
		}
		pFrontData = _queue.front().data;
		return _queue.front().pushedTime;
	}
开发者ID:Willie-Weichi-Yu,项目名称:OpenCCTV,代码行数:8,代码来源:ConcurrentQueue.hpp


示例14: 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


示例15: wait_and_pop

    bool wait_and_pop(T& data, boost::posix_time::microseconds waitTime)
    {
        boost::system_time            timeout = boost::get_system_time() + waitTime;
        boost::mutex::scoped_lock     lockHandle(mutexHandle);

        if (condFlag.timed_wait(lockHandle, timeout,
                                isEmpty(&queueHandle))) {
            data = queueHandle.front();
            queueHandle.pop();
            condFlag.notify_all();

            return true;
        }
        else {
            return false;
        }
    }
开发者ID:hvthaibk,项目名称:ccrunch,代码行数:17,代码来源:cThreadBoost.hpp


示例16: relative_timed_wait_with_predicate

 void relative_timed_wait_with_predicate()
 {
     boost::unique_lock<boost::mutex> lock(mutex);
     if(cond_var.timed_wait(lock,boost::posix_time::seconds(timeout_seconds),check_flag(flag)) && flag)
     {
         ++woken;
     }
 }
开发者ID:AlexMioMio,项目名称:boost,代码行数:8,代码来源:condition_test_common.hpp


示例17: operator

 void operator()()
 {
     boost::unique_lock<boost::mutex> lk(mut);
     while(!done)
     {
         cond.wait(lk);
     }
 }
开发者ID:BackupTheBerlios,项目名称:airdc-svn,代码行数:8,代码来源:test_thread.cpp


示例18: moneyReceived

 virtual void moneyReceived(const string &txId, uint64_t amount)
 {
     std::cout << "wallet: " << wallet->mainAddress() << "**** just received money ("
               << txId  << ", " << wallet->displayAmount(amount) << ")" << std::endl;
     total_rx += amount;
     receive_triggered = true;
     cv_receive.notify_one();
 }
开发者ID:Bluecoreg,项目名称:monero,代码行数:8,代码来源:main.cpp


示例19: push

void Main::push(Command cmd) {
	boost::lock_guard<boost::mutex> lock(libcec_sync);
	if( running )
	{
		commands.push(cmd);
		libcec_cond.notify_one();
	}
}
开发者ID:KingBonecrusher,项目名称:libcec-daemon,代码行数:8,代码来源:main.cpp


示例20: pop

	T pop()
	{
		boost::mutex::scoped_lock lock(_mutex);

		while(_queue.empty())
		{
			_conditionVar.wait(lock);
		}

		T result =_queue.front();
		_queue.pop();

		lock.unlock();
		_conditionVar.notify_one();

		return result;
	}
开发者ID:tisserapac,项目名称:OpenCCTV-Workshop,代码行数:17,代码来源:ImageQueue.hpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ boost::condition_variable_any类代码示例发布时间:2022-05-31
下一篇:
C++ boost::condition类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap