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


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

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


在下文中一共展示了thread_group类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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:

    ~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

示例3:

 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

示例4:

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

示例5:

 ~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

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

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

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

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

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

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

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

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

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

示例15: stop

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


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