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

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

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

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



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

示例1: main

int main()
{
  {
    boost::thread_group threads;
    for (int i = 0; i < 3; ++i)
        threads.create_thread(&increment_count);
    threads.join_all();
  }
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
  {
    boost::thread_group threads;
    for (int i = 0; i < 3; ++i)
        threads.create_thread(&increment_count);
    threads.interrupt_all();
    threads.join_all();
  }
#endif
  {
    boost::thread_group threads;
    boost::thread* th = new boost::thread(&increment_count);
    threads.add_thread(th);
    BOOST_TEST(! threads.is_this_thread_in());
    threads.join_all();
  }
  {
    boost::thread_group threads;
    boost::thread* th = new boost::thread(&increment_count);
    threads.add_thread(th);
    BOOST_TEST(threads.is_thread_in(th));
    threads.remove_thread(th);
    BOOST_TEST(! threads.is_thread_in(th));
    th->join();
  }
  {
    {
      boost::unique_lock<boost::mutex> lock(mutex);
      boost::thread* th2 = new boost::thread(&increment_count_2);
      threads2.add_thread(th2);
    }
    threads2.join_all();
  }
  return boost::report_errors();
}
开发者ID:MisterTea,项目名称:MAMEHub,代码行数:43,代码来源:thread_group.cpp


示例2: waitTermination

void waitTermination( boost::thread_group& threads, std::initializer_list< int > signals = { SIGINT, SIGTERM, SIGQUIT } )
{
     sigset_t sset;

     sigemptyset( &sset );

     for( const auto each: signals )
     {
          sigaddset( &sset, each );
     }

     sigprocmask( SIG_BLOCK, &sset, nullptr );

     std::cout << "threads running: " << threads.size() << "; main thread waiting for termination signals...\n";

     int sig = 0;
     sigwait( &sset, &sig );

     std::cout << "termination signal " << sig << " has been caught\n" << "interrupting threads...\n";

     threads.interrupt_all();
}
开发者ID:alexen,项目名称:using_rabbitmq,代码行数:22,代码来源:main.cpp


示例3: WorkerThread

/**
 * Note: Caller must hold m_Mutex
 */
void ThreadPool::Queue::SpawnWorker(boost::thread_group& group)
{
	for (size_t i = 0; i < sizeof(Threads) / sizeof(Threads[0]); i++) {
		if (Threads[i].State == ThreadDead) {
			Log(LogDebug, "base", "Spawning worker thread.");

			Threads[i] = WorkerThread(ThreadIdle);
			Threads[i].Thread = group.create_thread(boost::bind(&ThreadPool::WorkerThread::ThreadProc, boost::ref(Threads[i]), boost::ref(*this)));

			break;
		}
	}
}
开发者ID:CSRedRat,项目名称:icinga2,代码行数:16,代码来源:threadpool.cpp


示例4: RunDacrs

std::tuple<bool, boost::thread*> RunDacrs(int argc, char* argv[]) {
	boost::thread* detectShutdownThread = NULL;
	static boost::thread_group threadGroup;
	SetupEnvironment();

	bool fRet = false;

	// Connect Dacrsd signal handlers
	noui_connect();

	fRet = AppInit(argc, argv, threadGroup);

	detectShutdownThread = new boost::thread(boost::bind(&DetectShutdownThread, &threadGroup));

	if (!fRet) {
		if (detectShutdownThread)
			detectShutdownThread->interrupt();

		threadGroup.interrupt_all();
	}
	return std::make_tuple(fRet, detectShutdownThread);
}
开发者ID:hdczsf,项目名称:dacrs,代码行数:22,代码来源:systestbase.cpp


示例5:

    ~TestingSetup()
    {
        threadGroup.interrupt_all();
        threadGroup.join_all();
        Bitcredit_UnregisterNodeSignals(Credits_NetParams()->GetNodeSignals());
#ifdef ENABLE_WALLET
        delete bitcoin_pwalletMain;
        bitcoin_pwalletMain = NULL;
        delete bitcredit_pwalletMain;
        bitcredit_pwalletMain = NULL;
        delete deposit_pwalletMain;
        deposit_pwalletMain = NULL;
#endif
        delete credits_pcoinsTip;
        delete bitcredit_pcoinsdbview;
        delete bitcredit_pblocktree;

        delete bitcoin_pcoinsTip;
        delete bitcoin_pcoinsdbview;
        delete bitcoin_pblocktree;
#ifdef ENABLE_WALLET
        bitcoin_bitdb.Flush(true);
        bitcredit_bitdb.Flush(true);
        deposit_bitdb.Flush(true);
#endif
        boost::filesystem::remove_all(pathTemp);
    }
开发者ID:credits-currency,项目名称:credits,代码行数:27,代码来源:test_credits.cpp


示例6:

 parallel_test()
 {
     group_.add_thread( new boost::thread(&parallel_test::insert_sleep_removes_aspect1, this) );
     group_.add_thread( new boost::thread(&parallel_test::insert_sleep_removes_aspect2, this) );
     group_.add_thread( new boost::thread(&parallel_test::find_and_access, this) );
     group_.add_thread( new boost::thread(&parallel_test::insert_sleep_aspect1, this) );
     group_.add_thread( new boost::thread(&parallel_test::use_sleep_remove_aspect1, this) );
 }
开发者ID:caomw,项目名称:Boost.Application,代码行数:8,代码来源:aspect_map_test.cpp


示例7:

 virtual ~Log()
 {
     _isStopping = true;
     _threadPool.interrupt_all();
     _threadPool.join_all();
     _stringLoggerThread.interrupt();
     _stringLoggerThread.join();
 }
开发者ID:ankithbti,项目名称:fitiedCoreCpp,代码行数:8,代码来源:Log.hpp


示例8:

 ~TestingSetup()
 {
     threadGroup.interrupt_all();
     threadGroup.join_all();
     delete pwalletMain;
     pwalletMain = NULL;
     delete pcoinsTip;
     delete pcoinsdbview;
     delete pblocktree;
     bitdb.Flush(true);
     boost::filesystem::remove_all(pathTemp);
 }
开发者ID:ColoradoPay,项目名称:CPAY,代码行数:12,代码来源:test_bitcoin.cpp


示例9: start

    void start()
    {
        if (m_threads.size() > 0)
        {   return; }

        for(ios_type& ios : m_io_services)
        {
            m_threads.create_thread(
                boost::bind(&ios_type::run, 
                    boost::ref(ios)));
        }
    }
开发者ID:chronolaw,项目名称:professional_boost,代码行数:12,代码来源:io_service_pool.hpp


示例10: run_test

void client::run_test()
{
	unsigned optimal_threads_count = boost::thread::hardware_concurrency();

	if (optimal_threads_count == 0)
		optimal_threads_count = 1;

	ostream_ << "Create " << optimal_threads_count << " threads for client" << std::endl;

	for (unsigned i = 0; i < optimal_threads_count; ++i)
		threads_.add_thread(new boost::thread([this, i] () { thread_func(i); }));

	threads_.join_all();
	ostream_ << "All client's threads done" << std::endl;
}
开发者ID:sfff,项目名称:example,代码行数:15,代码来源:example.cpp


示例11: UnregisterNodeSignals

    ~TestingSetup()
    {
        threadGroup.interrupt_all();
        threadGroup.join_all();
        UnregisterNodeSignals(GetNodeSignals());
#ifdef ENABLE_WALLET
        delete pwalletMain;
        pwalletMain = NULL;
#endif
        delete pblocktree;
	delete pviewTip;
#ifdef ENABLE_WALLET
        bitdb.Flush(true);
#endif
        boost::filesystem::remove_all(pathTemp);
    }
开发者ID:JacobBruce,项目名称:Cryptonite,代码行数:16,代码来源:test_bitcoin.cpp


示例12: TestingSetup

    TestingSetup() {
        fPrintToDebugLog = false; // don't want to write to debug.log file
        noui_connect();
#ifdef ENABLE_WALLET
        bitdb.MakeMock();
#endif
        pathTemp = GetTempPath() / strprintf("test_bitcoin_%lu_%i", (unsigned long)GetTime(), (int)(GetRand(100000)));
        boost::filesystem::create_directories(pathTemp);
        mapArgs["-datadir"] = pathTemp.string();
	mapArgs["-testnet"] = "true";
        pblocktree = new CBlockTreeDB(1 << 20, true);
        pviewTip = new TrieView();
	LoadBlockIndex();
	printf("Loaded\n");
        // If the loaded chain has a wrong genesis, bail out immediately
        // (we're likely using a testnet datadir, or the other way around).
        if (!mapBlockIndex.empty() && chainActive.Genesis() == NULL)
        	printf("Incorrect or no genesis block found. Wrong datadir for network?");
        InitBlockIndex();
	printf("Init Done\n");
#ifdef ENABLE_WALLET
        bool fFirstRun;
        pwalletMain = new CWallet("wallet.dat");
        pwalletMain->LoadWallet(fFirstRun);
        RegisterWallet(pwalletMain);
#endif
        nScriptCheckThreads = 3;
        for (int i=0; i < nScriptCheckThreads-1; i++)
            threadGroup.create_thread(&ThreadScriptCheck);
        RegisterNodeSignals(GetNodeSignals());
    }
开发者ID:JacobBruce,项目名称:Cryptonite,代码行数:31,代码来源:test_bitcoin.cpp


示例13: start

	void start(size_type threadcnt_arg)
	{
		// one cannot start an empty thread group.
		if (0 == threadcnt_arg)
			NYAN_FAIL_IFZERO(threadcnt_arg);
		else
		{
			// [mlr] i use a barrier to ensure that that all service loops start
			// at the same time. otherwise, there could be race conditions
			// during their initialization phase. i need to add 1 because
			// my thread is going to wait on this barrier too.
			// [mlr][todo] does Service need to support an
			// explicit initialization phase? i think perhaps it does.
			boost::barrier *ready = new boost::barrier(threadcnt_arg + 1);
			// i now start up each service loop on a separate thread.
			my_threads.reserve(threadcnt_arg);
			for (size_type i = 0; i < threadcnt_arg; ++i)
			{
			   std::ostringstream name;
			   name << "pool thread " << i;
	         thread_type * const t =
	               new thread_type(*ready, name.str());
	         my_threads.push_back(t);
				my_group.create_thread(boost::ref(*t));
			}
			// now, i wait for all of the threads to signal that
			// they're ready to run their main loop.
			std::cout << "main pool thread waiting for barrier."
			      << std::endl;
			ready->wait();
         std::cout << "main pool thread continuing."
               << std::endl;
		}
	}
开发者ID:fmrl,项目名称:blanchett,代码行数:34,代码来源:pool.hpp


示例14: start

void AsyncSpinnerImpl::start()
{
  boost::mutex::scoped_lock lock(mutex_);

  if (continue_)
    return;

  boost::recursive_mutex::scoped_try_lock spinlock(spinmutex);
  if (!spinlock.owns_lock()) {
    ROS_WARN("AsyncSpinnerImpl: Attempt to start() an AsyncSpinner failed "
             "because another AsyncSpinner is already running. Note that the "
             "other AsyncSpinner might not be using the same callback queue "
             "as this AsyncSpinner, in which case no callbacks in your "
             "callback queue will be serviced.");
    return;
  }
  spinlock.swap(member_spinlock);

  continue_ = true;

  for (uint32_t i = 0; i < thread_count_; ++i)
  {
    threads_.create_thread(boost::bind(&AsyncSpinnerImpl::threadFunc, this));
  }
}
开发者ID:1ee7,项目名称:micROS-drt,代码行数:25,代码来源:spinner.cpp


示例15: TestingSetup

    TestingSetup() {
        fPrintToDebugLog = false; // don't want to write to debug.log file
        SelectParams(CBaseChainParams::UNITTEST);
        noui_connect();
#ifdef ENABLE_WALLET
        bitdb.MakeMock();
#endif
        pathTemp = GetTempPath() / strprintf("test_bitcoin_%lu_%i", (unsigned long)GetTime(), (int)(GetRand(100000)));
        boost::filesystem::create_directories(pathTemp);
        mapArgs["-datadir"] = pathTemp.string();
        pblocktree = new CBlockTreeDB(1 << 20, true);
        pcoinsdbview = new CCoinsViewDB(1 << 23, true);
        pcoinsTip = new CCoinsViewCache(pcoinsdbview);
        InitBlockIndex();
#ifdef ENABLE_WALLET
        bool fFirstRun;
        pwalletMain = new CWallet("wallet.dat");
        pwalletMain->LoadWallet(fFirstRun);
        RegisterValidationInterface(pwalletMain);
#endif
        nScriptCheckThreads = 3;
        for (int i=0; i < nScriptCheckThreads-1; i++)
            threadGroup.create_thread(&ThreadScriptCheck);
        RegisterNodeSignals(GetNodeSignals());
    }
开发者ID:86me,项目名称:skidoo,代码行数:25,代码来源:test_bitcoin.cpp


示例16: thread

void thread(FFMPEGData &vidData)
{
	int counter = 0;
	// changed this to use member function.
	if (vidData.startFFMPEG() < 0)
	{
		printf("should not get here.\n");
	}
	plays.add_thread(new boost::thread(play, vidData));
	while (true)
	{
		printf("\t\tthread count = %d\n", counter);
		// Read frames from the stream.
		if (av_read_frame(vidData.pFormatCtx, &vidData.pack[counter]) != AVERROR(EAGAIN))
		{
			if (counter < packetNum)
			{
				counter++;
			}
			else
			{
				counter = 0;
			}
		}

		//Sleep(25);
	}
}
开发者ID:lorengaravaglia,项目名称:thesis-scripts,代码行数:28,代码来源:Video+Player.cpp


示例17: ThreadPool

 /// @brief Constructor.
 explicit ThreadPool(std::size_t pool_size)
     :  running_(true), complete_(true),
        available_(pool_size), total_(pool_size) {
     for ( std::size_t i = 0; i < pool_size; ++i ) {
         threads_.create_thread(
             boost::bind(&ThreadPool::main_loop, this));
     }
 }
开发者ID:Caffe-MPI,项目名称:Caffe-MPI.github.io,代码行数:9,代码来源:thread_pool.hpp


示例18: stop

void stop(int sig)
{
	if (!die) {
		die = true;
		comm->stop();
		monitorThreads.interrupt_all();
	}
}
开发者ID:hans511002,项目名称:erydb,代码行数:8,代码来源:slavenode.cpp


示例19: Log

 Log(int numOfConsumerThreads = 1) :
 _isStopping(false),
 _stringLoggerThread(boost::bind(&Log::consumeStringLog, this))
 {
     for (int i = 0; i < numOfConsumerThreads; ++i)
     {
         _threadPool.create_thread(boost::bind(&Log::consumeToLog, this));
     }
 }
开发者ID:ankithbti,项目名称:fitiedCoreCpp,代码行数:9,代码来源:Log.hpp


示例20: x

            bench_atomic(size_t thread_count,
                              size_t iteration_count)
                : x(0)
                , iteration_count(0) {
                this->iteration_count = iteration_count;
                for (size_t i = 0; i < thread_count; ++i) {
				    threads.create_thread( boost::bind(&bench_atomic::do_test, this) );
                }
            }
开发者ID:drednout,项目名称:cpp_bench,代码行数:9,代码来源:main.cpp



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ boost::thread_specific_ptr类代码示例发布时间:2022-05-31
下一篇:
C++ boost::thread类代码示例发布时间: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