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


C++ Thread函数代码示例

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


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

示例1: if

void image_info::adjustThreads()
{
    int new_threads = nr_threads - threads.size();

    if (new_threads == 0)
    {
        return;
    }
    else if (new_threads > 0)
    {
        for (int i = 0; i < new_threads; i++)
        {
            // FIXME: avoid leaking the memory for RenderThread
            threads.push_back(Thread(new RenderThread(this)));
        }
    }
    else
    {
        // this is inefficient but we don't know which threads are going to
        // pick up the quit notices, so we don't know which threads we
        // should call join on, so just delete all of them and create
        // the new number of threads.

        stopThreads();
        adjustThreads();
    }
}
开发者ID:oskusalerma,项目名称:gfract,代码行数:27,代码来源:image_info.cpp

示例2: MOZ_ASSERT

void
BenchmarkPlayback::MainThreadShutdown()
{
  MOZ_ASSERT(OnThread());

  if (mDecoder) {
    mDecoder->Flush();
    mDecoder->Shutdown();
    mDecoder = nullptr;
  }

  mDecoderTaskQueue->BeginShutdown();
  mDecoderTaskQueue->AwaitShutdownAndIdle();
  mDecoderTaskQueue = nullptr;

  if (mTrackDemuxer) {
    mTrackDemuxer->Reset();
    mTrackDemuxer->BreakCycles();
    mTrackDemuxer = nullptr;
  }

  RefPtr<Benchmark> ref(mMainThreadState);
  Thread()->AsTaskQueue()->BeginShutdown()->Then(
    ref->Thread(), __func__,
    [ref]() {  ref->Dispose(); },
    []() { MOZ_CRASH("not reached"); });
}
开发者ID:cbradley857,项目名称:gecko-dev,代码行数:27,代码来源:Benchmark.cpp

示例3: Thread

void CPacketQueue::Init()
{
	gEnv->pLog->Log(TITLE "CPacketQueue::Init()");

	std::thread Thread(&CPacketQueue::Thread, this);
	Thread.detach();
}
开发者ID:aronarts,项目名称:FireNET,代码行数:7,代码来源:PacketQueue.cpp

示例4: Correct_Queue_range

/** This test case checks that the CCheckQueue works properly
 * with each specified size_t Checks pushed.
 */
static void Correct_Queue_range(std::vector<size_t> range)
{
    auto small_queue = std::unique_ptr<Correct_Queue>(new Correct_Queue {QUEUE_BATCH_SIZE});
    boost::thread_group tg;
    for (auto x = 0; x < nScriptCheckThreads; ++x) {
       tg.create_thread([&]{small_queue->Thread();});
    }
    // Make vChecks here to save on malloc (this test can be slow...)
    std::vector<FakeCheckCheckCompletion> vChecks;
    for (auto i : range) {
        size_t total = i;
        FakeCheckCheckCompletion::n_calls = 0;
        CCheckQueueControl<FakeCheckCheckCompletion> control(small_queue.get());
        while (total) {
            vChecks.resize(std::min(total, (size_t) InsecureRandRange(10)));
            total -= vChecks.size();
            control.Add(vChecks);
        }
        BOOST_REQUIRE(control.Wait());
        if (FakeCheckCheckCompletion::n_calls != i) {
            BOOST_REQUIRE_EQUAL(FakeCheckCheckCompletion::n_calls, i);
            BOOST_TEST_MESSAGE("Failure on trial " << i << " expected, got " << FakeCheckCheckCompletion::n_calls);
        }
    }
    tg.interrupt_all();
    tg.join_all();
}
开发者ID:iobond,项目名称:aib,代码行数:30,代码来源:checkqueue_tests.cpp

示例5: _tmain

int _tmain(int argc, _TCHAR* argv[])
{
	UNREFERENCED_PARAMETER(argc);
	UNREFERENCED_PARAMETER(argv);
    
	try
	{
		AC::Semaphore Tickets(NUM_TICKETS, NUM_TICKETS);
		std::vector<AC::Thread> Threads;
		for (unsigned short i = 0; i < NUM_SELLERS; i++)
		{
			AC::Thread Thread(new Seller(Tickets, i+1));
			Thread.Start();
			Threads.push_back(Thread);
		}
		for (unsigned short i = 0; i < Threads.size(); i++)
			Threads[i].Wait();
	}
	catch(std::exception& ex)
	{
		fprintf(stderr, "Exception: %s\n", ex.what());
	}

	return 0;
}
开发者ID:rusamentiaga,项目名称:LibAC,代码行数:25,代码来源:Sample-Semaphore.cpp

示例6: Thread

void Vm::startsWith(const byte* const beg, const byte* const end, const uint64_t startOffset, HitCallback hitFn, void* userData) {
  CurHitFn = hitFn;
  UserData = userData;
  const Instruction* base = &(*Prog)[0];
  uint64_t offset = startOffset;

  if (Prog->First[*beg]) {
    for (ThreadList::const_iterator t(First.begin()); t != First.end(); ++t) {
      Active.emplace_back(
      #ifdef _MSC_VER
        Thread(t->PC, Thread::NOLABEL, offset, Thread::NONE)
      #else
        t->PC, Thread::NOLABEL, offset, Thread::NONE
      #endif
      );
    }

    for (const byte* cur = beg; cur < end; ++cur, ++offset) {
      for (ThreadList::iterator t(Active.begin()); t != Active.end(); ++t) {
        _executeThread(base, t, cur, offset);
      }

      _cleanup();

      if (Active.empty()) {
        // early exit if threads die out
        break;
      }
    }
  }

  closeOut(hitFn, userData);
  reset();
}
开发者ID:queer1,项目名称:liblightgrep,代码行数:34,代码来源:vm.cpp

示例7: Thread

/// <summary>
/// Create the thread.
/// </summary>
/// <param name="threadProc">Thread enty point</param>
/// <param name="arg">Thread argument.</param>
/// <param name="flags">Thread creation flags</param>
/// <returns>New thread object</returns>
Thread ProcessThreads::CreateNew( ptr_t threadProc, ptr_t arg, DWORD flags /*= 0*/ )
{
    HANDLE hThd = NULL;
    _core.native()->CreateRemoteThreadT( hThd, threadProc, arg, flags );

    return Thread( hThd, &_core );
}
开发者ID:CaptainBigSmoke,项目名称:Blackbone,代码行数:14,代码来源:Threads.cpp

示例8: CreateToolhelp32Snapshot

/// <summary>
/// Gets all process threads
/// </summary>
/// <param name="dontUpdate">Return already existing thread list</param>
/// <returns>Threads collection</returns>
std::vector<Thread>& ProcessThreads::getAll( bool dontUpdate /*= false*/ )
{
    if (dontUpdate)
        return _threads;

    HANDLE hThreadSnapshot = CreateToolhelp32Snapshot( TH32CS_SNAPTHREAD, 0 );

    _threads.clear();

    if (hThreadSnapshot != INVALID_HANDLE_VALUE)
    {
        THREADENTRY32 tEntry = { 0 };
        tEntry.dwSize = sizeof(THREADENTRY32);

        // Iterate threads
        for (BOOL success = Thread32First( hThreadSnapshot, &tEntry ); 
              success == TRUE;
              success = Thread32Next( hThreadSnapshot, &tEntry ))
        {
            if (tEntry.th32OwnerProcessID != _core.pid())
                continue;

            _threads.emplace_back( Thread( tEntry.th32ThreadID, &_core ) );
        }

        CloseHandle( hThreadSnapshot );
    }

    return _threads;
}
开发者ID:CaptainBigSmoke,项目名称:Blackbone,代码行数:35,代码来源:Threads.cpp

示例9: CtrlHandler

BOOL WINAPI CtrlHandler(DWORD CtrlType)
{
	switch(CtrlType)
	{
	case CTRL_C_EVENT:
		return TRUE;

	case CTRL_BREAK_EVENT:
		if(!CancelIoInProgress().Signaled())
		{
			CancelIoInProgress().Set();
			Thread(&Thread::detach, &CancelSynchronousIoWrapper, Global->MainThreadHandle());
		}
		WriteInput(KEY_BREAK);

		if (Global->CtrlObject && Global->CtrlObject->Cp())
		{
			if (Global->CtrlObject->Cp()->LeftPanel && Global->CtrlObject->Cp()->LeftPanel->GetMode()==PLUGIN_PANEL)
				Global->CtrlObject->Plugins->ProcessEvent(Global->CtrlObject->Cp()->LeftPanel->GetPluginHandle(),FE_BREAK, ToPtr(CtrlType));

			if (Global->CtrlObject->Cp()->RightPanel && Global->CtrlObject->Cp()->RightPanel->GetMode()==PLUGIN_PANEL)
				Global->CtrlObject->Plugins->ProcessEvent(Global->CtrlObject->Cp()->RightPanel->GetPluginHandle(),FE_BREAK, ToPtr(CtrlType));
		}
		return TRUE;

	case CTRL_CLOSE_EVENT:
		Global->CloseFAR=TRUE;
		Global->AllowCancelExit=FALSE;

		// trick to let wmain() finish correctly
		ExitThread(1);
		//return TRUE;
	}
	return FALSE;
}
开发者ID:chapgaga,项目名称:farmanager,代码行数:35,代码来源:interf.cpp

示例10: _tmain

int _tmain(int argc, _TCHAR* argv[])
{
	UNREFERENCED_PARAMETER(argc);
	UNREFERENCED_PARAMETER(argv);

	try
	{
		AC::Event Event(FALSE, TRUE);
		std::vector<AC::Thread> Threads;
		for (unsigned short i = 1; i <= NUM_THREADS; i++)
		{
			AC::Thread Thread(new TaskPrint(Event, i));
			Thread.Start();
			Threads.push_back(Thread);
		}
		Sleep(DELAY_MS);
		Event.SetEvent();
		for (unsigned short i = 0; i < Threads.size(); i++)
			Threads[i].Wait();
	}
	catch(std::exception& ex)
	{
		fprintf(stderr, "Exception: %s\n", ex.what());
	}

	return 0;
}
开发者ID:rusamentiaga,项目名称:LibAC,代码行数:27,代码来源:Sample-Event.cpp

示例11: System_Threading_Thread_ctorParam

tAsyncCall* System_Threading_Thread_ctorParam(PTR pThis_, PTR pParams, PTR pReturnValue) {
	tThread *pThread = Thread();
	pThread->startDelegate = ((PTR*)pParams)[0];
	*(HEAP_PTR*)pReturnValue = (HEAP_PTR)pThread;
	pThread->hasParam = 1;
	return NULL;
}
开发者ID:babychupchup,项目名称:dotNetAnywhere-wb,代码行数:7,代码来源:System.Threading.Thread.c

示例12: THROW_LAST_ERROR_EXCEPTION

	ThreadList Thread::GetList(UInt32 processId)
	{
		Handle hSnapshot = ::CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, processId);
		if (!hSnapshot.IsValid())
		{
			THROW_LAST_ERROR_EXCEPTION();
		}

		THREADENTRY32 threadEntry = {0};
		threadEntry.dwSize = sizeof(threadEntry);

		BOOL success = ::Thread32First(hSnapshot, &threadEntry);
		if (!success)
		{
			THROW_LAST_ERROR_EXCEPTION();
		}

		ThreadList list;
		while (success)
		{
			if (threadEntry.th32OwnerProcessID == processId)
			{
				list.push_back(Thread(threadEntry.th32ThreadID));
			}
			success = ::Thread32Next(hSnapshot, &threadEntry);
		}

		return list;
	}
开发者ID:alexander-borodulya,项目名称:WinToolsLib,代码行数:29,代码来源:Thread.cpp

示例13: _tmain

int _tmain(int argc, _TCHAR* argv[])
{
	UNREFERENCED_PARAMETER(argc);
	UNREFERENCED_PARAMETER(argv);

	srand((unsigned int)time(NULL));

	try
	{
		AC::SharedQueue<Pair> InputQueue(NUM_POLYNOMIALS), OutputQueue(NUM_POLYNOMIALS);
		AC::Thread Thread(new MathTask(InputQueue, OutputQueue));
		Thread.Start();
		
		for (unsigned short i = 0; i < NUM_POLYNOMIALS; i++)
		{
			Pair p;
			p.first = rand();
			InputQueue.Push(p);
		}
		for (unsigned short i = 0; i < NUM_POLYNOMIALS; i++)
		{
			Pair p = OutputQueue.Pop();
			printf( "El valor del polinomio para x=%f es y=%f\n", p.first, p.second);
		}		

		Thread.Wait();
	}
	catch(std::exception& ex)
	{
		fprintf(stderr, "Exception: %s\n", ex.what());
	}
	
	return 0;
}
开发者ID:rusamentiaga,项目名称:LibAC,代码行数:34,代码来源:Sample-SharedQueue.cpp

示例14: MOZ_ASSERT

void BenchmarkPlayback::DemuxNextSample() {
  MOZ_ASSERT(OnThread());

  RefPtr<Benchmark> ref(mGlobalState);
  RefPtr<MediaTrackDemuxer::SamplesPromise> promise =
      mTrackDemuxer->GetSamples();
  promise->Then(
      Thread(), __func__,
      [this, ref](RefPtr<MediaTrackDemuxer::SamplesHolder> aHolder) {
        mSamples.AppendElements(std::move(aHolder->mSamples));
        if (ref->mParameters.mStopAtFrame &&
            mSamples.Length() == ref->mParameters.mStopAtFrame.ref()) {
          InitDecoder(std::move(*mTrackDemuxer->GetInfo()));
        } else {
          Dispatch(
              NS_NewRunnableFunction("BenchmarkPlayback::DemuxNextSample",
                                     [this, ref]() { DemuxNextSample(); }));
        }
      },
      [this, ref](const MediaResult& aError) {
        switch (aError.Code()) {
          case NS_ERROR_DOM_MEDIA_END_OF_STREAM:
            InitDecoder(std::move(*mTrackDemuxer->GetInfo()));
            break;
          default:
            Error(aError);
            break;
        }
      });
}
开发者ID:jasonLaster,项目名称:gecko-dev,代码行数:30,代码来源:Benchmark.cpp

示例15: NazaraError

	void Music::Play()
	{
		#if NAZARA_AUDIO_SAFE
		if (!m_impl)
		{
			NazaraError("Music not created");
			return;
		}
		#endif

		// Maybe we are already playing
		if (m_impl->streaming)
		{
			switch (GetStatus())
			{
				case SoundStatus_Playing:
					SetPlayingOffset(0);
					break;

				case SoundStatus_Paused:
					alSourcePlay(m_source);
					break;

				default:
					break; // We shouldn't be stopped
			}
		}
		else
		{
			// Starting streaming's thread
			m_impl->streaming = true;
			m_impl->thread = Thread(&Music::MusicThread, this);
		}
	}
开发者ID:danrleinascimento,项目名称:NazaraEngine,代码行数:34,代码来源:Music.cpp


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