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


C++ thread_group::create_thread方法代码示例

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


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

示例1: TestingSetup

 TestingSetup() {
     fPrintToDebugger = true; // don't want to write to debug.log file
     noui_connect();
     bitdb.MakeMock();
     pathTemp = GetTempPath() / strprintf("test_servx_%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();
     bool fFirstRun;
     pwalletMain = new CWallet("wallet.dat");
     pwalletMain->LoadWallet(fFirstRun);
     RegisterWallet(pwalletMain);
     nScriptCheckThreads = 3;
     for (int i=0; i < nScriptCheckThreads-1; i++)
         threadGroup.create_thread(&ThreadScriptCheck);
 }
开发者ID:ServX,项目名称:servx,代码行数:19,代码来源:test_bitcoin.cpp

示例2: start

void TaskManager::start()
{
    ThreadedList lst;
    for (int i = 0; i < 5; ++i) {
        TaskExecuter tex(i);
        tex.setList(&lst);
        m_threadGroup.create_thread(tex);
    }

    chrono::duration<uint32_t, milli> d(1000);
    for (int i = 0; i < 5; i++) {
        cout << "std called\n\r";
        this_thread::sleep_for(d);
    }

    for (auto str : lst.data()) {
        cout << str;
    }
}
开发者ID:CCJY,项目名称:coliru,代码行数:19,代码来源:main.cpp

示例3: main

int main()
{
    std::ifstream input(BINARY_DIR"/input.txt", std::ios::binary);
    SyncClass sc;
    for(int i = 0;i < THREADS_COUNT; i++)
        threads.create_thread(boost::bind(&SyncClass::writeMessage, &sc) );

    while(!input.eof()){
        Message msg(input);
        if(input.eof())
            break;
        boost::mutex::scoped_lock lock(queueMutex);
        msgQueue.push(msg);
    }
    sc.stopWorking();
    threads.join_all();

    return 0;
}
开发者ID:Gedeon-by,项目名称:cpp_craft_0314,代码行数:19,代码来源:binary_datafeed.cpp

示例4: TestingSetup

    TestingSetup() {
        fPrintToDebugLog = false; // don't want to write to debug.log file
        noui_connect();
#ifdef ENABLE_WALLET
        bitcoin_bitdb.MakeMock();
        bitcredit_bitdb.MakeMock();
        deposit_bitdb.MakeMock();
#endif
        pathTemp = GetTempPath() / strprintf("test_credits_%lu_%i", (unsigned long)GetTime(), (int)(GetRand(100000)));
        boost::filesystem::create_directories(pathTemp);
        mapArgs["-datadir"] = pathTemp.string();

        bitcredit_pblocktree = new Credits_CBlockTreeDB(1 << 20, true);
        bitcredit_pcoinsdbview = new Credits_CCoinsViewDB(1 << 23, true);
        credits_pcoinsTip = new Credits_CCoinsViewCache(*bitcredit_pcoinsdbview);

        bitcoin_pblocktree = new Bitcoin_CBlockTreeDB(1 << 20, true);
        bitcoin_pcoinsdbview = new Bitcoin_CCoinsViewDB(1 << 23, true);
        bitcoin_pcoinsTip = new Bitcoin_CCoinsViewCache(*bitcoin_pcoinsdbview);

        Bitcoin_InitBlockIndex();
        Credits_InitBlockIndex();

#ifdef ENABLE_WALLET
        bool fFirstRun;
        bitcoin_pwalletMain = new Bitcoin_CWallet("bitcoin_wallet.dat");
        bitcoin_pwalletMain->LoadWallet(fFirstRun);
        Bitcoin_RegisterWallet(bitcoin_pwalletMain);

        bitcredit_pwalletMain = new Credits_CWallet("credits_wallet.dat", &bitcredit_bitdb);
        bitcredit_pwalletMain->LoadWallet(fFirstRun, bitcredit_nAccountingEntryNumber);
        Bitcredit_RegisterWallet(bitcredit_pwalletMain);

        deposit_pwalletMain = new Credits_CWallet("deposit_wallet.dat", &deposit_bitdb);
        deposit_pwalletMain->LoadWallet(fFirstRun, deposit_nAccountingEntryNumber);
        Bitcredit_RegisterWallet(deposit_pwalletMain);
#endif
        bitcredit_nScriptCheckThreads = 3;
        for (int i=0; i < bitcredit_nScriptCheckThreads-1; i++)
            threadGroup.create_thread(&Bitcredit_ThreadScriptCheck);
        Bitcredit_RegisterNodeSignals(Credits_NetParams()->GetNodeSignals());
    }
开发者ID:credits-currency,项目名称:credits,代码行数:42,代码来源:test_credits.cpp

示例5: start

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

  if (continue_)
    return;

  boost::recursive_mutex::scoped_try_lock spinlock(spinmutex);
  if (not spinlock.owns_lock()) {
    ROS_ERROR("AsyncSpinnerImpl: Attempt to call spin from multiple "
              "threads.  We already spin multithreaded.");
    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:strawlab,项目名称:ros_comm,代码行数:22,代码来源:spinner.cpp

示例6: init

void init()
{
	// Initialize the DevIL framework.
	ilInit();

	// Initialize OpenGL
	glInit();

	// Give the scene a starting number of spheres.
	changeSphereCount(INITIAL_SPHERE_COUNT);
	
	// Create an image ID for our font texture.
	ILubyte fontId = ilGenImage();
	ilBindImage(fontId);

	if(!ilLoad(IL_PNG, "data/font.png"))
	{
		MessageBox(NULL, "Unable to load font texture.\nThere will be no interface.", "Could not load font.", MB_OK);
	}
	else
	{
		// Tell all existing TextFields the image ID to use.
		txtNumSpheres.setFontId(fontId);
		txtRenderFrames.setFontId(fontId);
		txtPhysicsFrames.setFontId(fontId);
		txtNumThreads.setFontId(fontId);

		txtInstructions.setFontId(fontId);
		txtInstructions.setColour(0xFFFFAA);
		txtInstructions.setText("Press +/- to add or remove spheres. 1 - 9 to set sphere size.");

		txtInstructions2.setFontId(fontId);
		txtInstructions2.setColour(0xFFFFAA);
		txtInstructions2.setText("Use the arrow keys and page up/down to control the sphere.");
	}

	int iCPUVals[4];
	cpuid(1, iCPUVals);

	bool sse4Support = false;
	if(iCPUVals[2] & (1 << 19))
	{
		sse4Support = true;
	}

#ifdef _SSE4
	if(!sse4Support && _SSE4)
	{
		txtInstructions.setColour(0xFF0000);
		txtInstructions.setText("Your computer does not support SSE4, please use a different version of this program.");
		displayError = true;

		numPhysicsThreads = 1;
	}
	else
#endif
	{
		// Setup performance checking, used to determine time difference
		// between physics thread runs.
		QueryPerformanceFrequency( &frequency );
		freq = (double)frequency.QuadPart / 1000.0;
		LARGE_INTEGER firstTime;
		QueryPerformanceCounter(&firstTime);

	#if _USE_MT
		// Get the number of physics threads to use from boost.
		numPhysicsThreads = boost::thread::hardware_concurrency();
	#else
		// Set that we're only using one thread, mostly for the purpose that
		// the physics function uses the number of threads for striding.
		numPhysicsThreads = 1;
	#endif

		updateTimes = new LARGE_INTEGER[numPhysicsThreads];
		physicsFrames = new int[numPhysicsThreads];

		for(int i = 0; i < numPhysicsThreads; i++)
		{
			updateTimes[i] = firstTime;
			physicsFrames[i] = 0;
	#if _USE_MT
			threads.create_thread(boost::bind(physicsThread, i));
	#endif
		}

		char buff[32];

		sprintf(buff, "Num threads: %d", numPhysicsThreads);
		txtNumThreads.setText(buff);
	}
}
开发者ID:astrellon,项目名称:GPP,代码行数:91,代码来源:main.cpp

示例7: main

int main(int argc, char **argv)
{

	// get and set locale language - BUG 5362
	string systemLang = "C";
	systemLang = funcexp::utf8::erydb_setlocale();

	BRM::logInit ( BRM::SubSystemLogId_workerNode );

	string nodeName;
	SlaveDBRMNode slave;
	string arg;
	int err = 0;
	ShmKeys keys;

	if (argc < 2) {
		ostringstream os;
		os << "Usage: " << argv[0] << " DBRM_WorkerN";
		cerr << os.str() << endl;
		log(os.str());
		fail();
		exit(1);
	}

	erydbdatafile::ERYDBPolicy::configERYDBPolicy();

	nodeName = argv[1];	
	try {
		comm = new SlaveComm(nodeName, &slave);
	}
	catch (exception &e) {
		ostringstream os;
		os << "An error occured: " << e.what();
		cerr << os.str() << endl;
		log(os.str());
		fail();
		exit(1);
	}
#ifdef SIGHUP
 	signal(SIGHUP, reset);
#endif
 	signal(SIGINT, stop);
	signal(SIGTERM, stop);
#ifdef SIGPIPE
	signal(SIGPIPE, SIG_IGN);
#endif

	if (!(argc >= 3 && (arg = argv[2]) == "fg"))
		err = fork();

	if (err == 0) {

		/* Start 4 threads to monitor write lock state */
		monitorThreads.create_thread(RWLockMonitor
				(&die, slave.getEMFLLockStatus(), keys.KEYRANGE_EMFREELIST_BASE));
		monitorThreads.create_thread(RWLockMonitor
				(&die, slave.getEMLockStatus(), keys.KEYRANGE_EXTENTMAP_BASE));
		monitorThreads.create_thread(RWLockMonitor
				(&die, slave.getVBBMLockStatus(), keys.KEYRANGE_VBBM_BASE));
		monitorThreads.create_thread(RWLockMonitor
				(&die, slave.getVSSLockStatus(), keys.KEYRANGE_VSS_BASE));

		try {
			oam::Oam oam;
			
			oam.processInitComplete("DBRMWorkerNode");
		}
		catch (exception &e) {
			ostringstream os;
			os << "failed to notify OAM: " << e.what();
			os << " continuing anyway";
			cerr << os.str() << endl;
			log(os.str(), logging::LOG_TYPE_WARNING);
		}

		try {
			comm->run();
		}
		catch (exception &e) {
			ostringstream os;
			os << "An error occurred: " << e.what();
			cerr << os.str() << endl;
			log(os.str());
			exit(1);
		}
	}
	else if (err < 0) {
		perror(argv[0]);
		log_errno(string(argv[0]));
		fail();
	}

	exit(0);
}
开发者ID:hans511002,项目名称:erydb,代码行数:94,代码来源:slavenode.cpp

示例8: exec

void exec(int id, bool threaded)
{
	if (threaded)
		std::cout << "thread:" << boost::this_thread::get_id() << ": " << id << std::endl;

	float* input = input_list[id];

#ifdef USE_OPENCL
	const cl::CommandQueue& queue = clQueues[id];
	const cl::Kernel& assignment = clClusterAssignment[id];
	const cl::Kernel& reposition = clClusterReposition[id];
	const cl::Kernel& reposition_k = clClusterReposition_k[id];
	const cl::Kernel& reposition_k_c = clClusterReposition_k_c[id];
	const cl::Kernel& cost = clComputeCost[id];

	const cl::Buffer& inputBuf = clInputBuf[id];
	const cl::Buffer& mappingBuf = clMappingBuf[id];
	const cl::Buffer& centroidBuf = clCentroidBuf[id];
	//const cl::Buffer& convergedBuf = clConvergedBuf[id];
	const cl::Buffer& reductionBuf = clReductionBuf[id];

	queue.enqueueWriteBuffer(inputBuf, CL_FALSE, 0, N * DIM * sizeof(float), (void*)input, NULL, NULL);
#endif

	for (int pass = id; pass < RUNS; pass += device_count) {

		float* reduction = new float[N];
		float* centroids = random_cluster_init(input);
		int* mapping = new int[N];
		centroids_list[pass] = centroids;
		mapping_list[pass] = mapping;

		util::Clock clock;
		clock.reset();

#ifdef USE_OPENCL
		queue.enqueueWriteBuffer(centroidBuf, CL_FALSE, 0, K * DIM * sizeof(float), (void*)centroids, NULL, NULL);

		for (int i = 0; i < ITERATIONS; ++i) {
			queue.enqueueNDRangeKernel(assignment, cl::NullRange, cl::NDRange(N), cl::NDRange(AM_LWS), NULL, NULL);

#ifdef CLUSTER_REPOSITION_K
			queue.enqueueNDRangeKernel(reposition_k, cl::NullRange, cl::NDRange(K), cl::NDRange(RP_LWS), NULL, NULL);
#else
			queue.enqueueNDRangeKernel(reposition, cl::NullRange, cl::NDRange(DIM), cl::NDRange(RP_LWS), NULL, NULL);
#endif
		}
		queue.enqueueNDRangeKernel(cost, cl::NullRange, cl::NDRange(N), cl::NDRange(CT_LWS), NULL, NULL);

		//queue.finish();

		queue.enqueueReadBuffer(centroidBuf, CL_FALSE, 0, K * DIM * sizeof(float), centroids, NULL, NULL);
		queue.enqueueReadBuffer(mappingBuf, CL_FALSE, 0, N * sizeof(int), mapping, NULL, NULL);
		queue.enqueueReadBuffer(reductionBuf, CL_TRUE, 0, N * sizeof(float), reduction, NULL, NULL);

		reduction_group.create_thread(boost::bind(reduce_cost, pass, reduction));


		//queue.finish();
#else
		for (int i = 0; i < ITERATIONS; ++i) {
			cluster_assignment(input, centroids, mapping);
			cluster_reposition(input, centroids, mapping);
			//if (cluster_reposition(input, centroids, mapping)) {
			//	std::cout << "Converged after " << i+1 << " iterations." << std::endl;
			//	break;
			//}
		}

		cost_list[pass] = cluster_compute_cost(input, centroids, mapping);
#endif

		float now = clock.get();
		std::cout << "Device: " << now << std::endl;
	}
/*
	float sum = 0.0f;
	for (int i = 0; i < N; ++i) {
		sum += treduction[i];
	}

	sum /= (float)N;

	std::cout << sum << std::endl;
*/
}
开发者ID:markusd,项目名称:gpgpu,代码行数:86,代码来源:kmeans.cpp

示例9: data

void M6Processor::Process(vector<fs::path>& inFiles, M6Progress& inProgress,
    uint32 inNrOfThreads)
{
    if (inFiles.size() >= inNrOfThreads)
        mUseDocQueue = false;
    else
    {
        mUseDocQueue = true;
        for (uint32 i = 0; i < inNrOfThreads; ++i)
            mDocThreads.create_thread([this]() { this->ProcessDocument(); });
    }

    if (inFiles.size() == 1)
    {
        M6DataSource data(inFiles.front(), inProgress);
        for (M6DataSource::iterator i = data.begin(); i != data.end(); ++i)
        {
            LOG(INFO, "M6Processor: processing file %s", i->mFilename.c_str());
            ProcessFile(i->mFilename, i->mStream);
            LOG(INFO, "M6Processor: done processing file %s", i->mFilename.c_str());
        }
    }
    else
    {
        if (inNrOfThreads > inFiles.size())
            inNrOfThreads = static_cast<uint32>(inFiles.size());

        for (uint32 i = 0; i < inNrOfThreads; ++i)
            mFileThreads.create_thread(
                [&inProgress, this]() { this->ProcessFile(inProgress); }
            );

        for (fs::path& file : inFiles)
        {
            if (not (mException == std::exception_ptr()))
                rethrow_exception(mException);

            if (not fs::exists(file))
            {
                cerr << "file missing: " << file << endl;
                continue;
            }

            mFileQueue.Put(file);
        }

        mFileQueue.Put(fs::path());

        // Now all the input files have been added to the queue.

        mFileThreads.join_all();
    }

    if (mUseDocQueue)
    {
        mDocQueue.Put(kSentinel);
        mDocThreads.join_all();
    }

    if (not (mException == std::exception_ptr()))
        rethrow_exception(mException);
}
开发者ID:cmbi,项目名称:mrs,代码行数:62,代码来源:M6Builder.cpp


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