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


C++ Thread::Join方法代码示例

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


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

示例1: test_rwlock

void test_rwlock(Ardb& db)
{
    WriteTask wtask;
    ReadTask rtask;
    std::map<int, int> mm;
    SpinRWLock lock;
    wtask.lock = &lock;
    wtask.mm = &mm;
    rtask.lock = &lock;
    rtask.mm = &mm;
    Thread* w = new Thread(&wtask);
    std::vector<Thread*> ts;
    for(uint32 i = 0; i < 10; i++)
    {
        Thread* r = new Thread(&rtask);
        r->Start();
        ts.push_back(r);
    }
    w->Start();
    w->Join();
    std::vector<Thread*>::iterator tit = ts.begin();
    while(tit != ts.end())
    {
        (*tit)->Join();
        tit++;
    }
    INFO_LOG("mm size=%u", mm.size());
}
开发者ID:DirektSPEED,项目名称:ardb,代码行数:28,代码来源:misc_testcase.cpp

示例2: Shutdown

void ovrJobThread::Shutdown()
{
	OVR_ASSERT( Jni == nullptr );	// DetachFromCurrentThread should have been called first
	OVR_ASSERT( MyThread != nullptr );

	MyThread->Join();

	delete MyThread;	// this will call Join()
	MyThread = nullptr;	
}
开发者ID:ejeinc,项目名称:Meganekko,代码行数:10,代码来源:JobManager.cpp

示例3: testThreadCreate

      /**
       * \brief Test the creation and join of thread. 
       */
      void testThreadCreate()
      {
        void* ret = NULL;
        Callback obj;
        Thread th = Thread(new ThreadArgImpl<Callback>(obj, &Callback::Call, NULL));

        th.Start(false);
        th.Join(&ret);

        CPPUNIT_ASSERT(ret == (void*)0xABCD);
      }
开发者ID:JerkWisdom,项目名称:zpublic,代码行数:14,代码来源:test-system.cpp

示例4: Run

	void Program::Run()
	{
		Thread* th = new Thread(new ThreadStart(DELEGATE_FUNC(Program::target1)));
		Thread* th2 = new Thread(new ThreadStart(DELEGATE_FUNC(Program::target2)));
		Console::WriteLine(new String("Start threads"));
		th->Start();
		th2->Start();
		Thread::Sleep(5000);
		Console::WriteLine(new String("Abort Target 2"));
		th2->Abort();
		Console::WriteLine(new String("Wait for Target 1 to finish (15 iterations)"));
		th->Join();
		Console::WriteLine(new String("Finished"));
	}
开发者ID:AlexAlbala,项目名称:AlterNative-Tests,代码行数:14,代码来源:Program.cpp

示例5: Shutdown

void JobManager::Shutdown()
{
	m_running = false;
	while (m_threads.size() > 0) {
		Thread* thread = m_threads.front();
		thread->Join();
		delete thread;

		m_threads.pop_front();
	}

	// finish out finished jobs
	Update();
}
开发者ID:2bitdreamer,项目名称:SD6_Engine,代码行数:14,代码来源:JobManager.cpp

示例6: dlltest

int __stdcall dlltest(int a, int b) noexcept {
	auto f = [](Utf8String s){
		std::printf("thread %u: tls = %s\n", (unsigned)::GetCurrentThreadId(), GetString().GetStr());
		GetString() = std::move(s);
		std::printf("thread %u: tls = %s\n", (unsigned)::GetCurrentThreadId(), GetString().GetStr());
	};

	Thread t;
	t.Create(Bind(f, "world"_u8s), false);
	f("hello"_u8s);
	t.Join();

	return a + b;
}
开发者ID:lhmouse,项目名称:MCF,代码行数:14,代码来源:main.cpp

示例7: testThreadCancel

      /**
       * \brief Test the cancelation of thread. 
       */
      void testThreadCancel()
      {
        void* ret = NULL;
        Callback obj;
        Thread th = Thread(new ThreadArgImpl<Callback>(obj, &Callback::Call2, NULL));

        th.Start(false);
        th.Stop();
        th.Join(&ret);
        
        /* on x86 it returns 0xffffffff
         * on x86-64 0xffffffffffffffff
         * so (void*)-1
         */
        CPPUNIT_ASSERT(ret == (void*)-1);
      }
开发者ID:JerkWisdom,项目名称:zpublic,代码行数:19,代码来源:test-system.cpp

示例8: main

int main(){
	signal(SIGHUP, HTTPServer::HUP_received);

	Config* con = Config::Instance();
	con->saveParam();
	int Port = atoi(con->lookupParam("Port").c_str());
	cerr << "opening a socket" << endl;
	Socket* masterSocket = new Socket();
	if (masterSocket->Listen(Port) < 0) { 
		// handle error
		cerr << "Error: the listen function has failed, OS cannot accept new connection" << endl; 
		return -1;
	}

	int LENGTH = 2;
	int count = 0;
	Thread* threads[LENGTH];
	for (int i = 0; i < LENGTH; i++)
		threads[i] = NULL;

	ssbuf* ssbuffer;
	Thread* thread;

	Thread* threadWatch = new Thread();
	threadWatch->Run(new ServWatcher(thread));

	MutexInstance::Instance();

	while ((ssbuffer = new ssbuf())->accept(masterSocket) != 0) {
		cout << (threads[count] == NULL) << endl;
		if (threads[count] == NULL) {
			cout << "created new" << endl;
			threads[count] = new Thread();
		}
		thread = threads[count];
		cout << "Opening new connection:"<<count<<endl;

		thread->Join();
		cout << "Joining"<<endl;
		cout << "Run:"<<thread->Run(new HTTPServer(thread, ssbuffer, masterSocket))<<endl;
		cout << "Running:"<<count<<endl;
		if (count++ > LENGTH-1)
			count = 0;
		if (HTTPServer::server_count <= 0) break;
	}
	return 0;
}
开发者ID:Arwid,项目名称:hserver,代码行数:47,代码来源:hserver.C

示例9: CancelAll

int ThreadPool::CancelAll() {
    int ret = 0;
    ThreadVec::iterator it = threads.end();
    while (it != threads.begin()) {
	it --;
	Thread *t = *it;
	if (t->Cancel() == -1 || t->Join() == -1) {
	    ret = -1;
	    break;
	}

	delete t;
	it = threads.erase(it);
    }
    
    return ret;
}
开发者ID:apir8181,项目名称:training,代码行数:17,代码来源:threadpool.cpp

示例10: startInteractiveSimulation

/**
 * Starts an Interactive simulation session
 * the runtime waits until a user shuts down the simulation
 */
int startInteractiveSimulation(int argc, char**argv, void* data)
{
  int retVal = -1;

  // ppriv - NO_INTERACTIVE_DEPENDENCY - for simpler debugging in Visual Studio
#ifndef NO_INTERACTIVE_DEPENDENCY
  initServiceInterfaceData(argc, argv, data);

  //Create the Control Server Thread
  Thread *threadSimulationControl = createControlThread();
  threadSimulationControl->Join();
  delete threadSimulationControl;

  std::cout << "simulation finished!" << std::endl;
#else
  std::cout << "Interactive Simulation not supported when LEAST_DEPENDENCY is defined!!!" << std::endl;
#endif
  return retVal; //TODO 20100211 pv return value implementation / error handling
}
开发者ID:,项目名称:,代码行数:23,代码来源:

示例11: Destroy

void ThreadPoolImpl::Destroy()
{
	if (!m_bCreate) {
		return;
	}

	do
	{
		//!should wait dead thread have been deleted.
		unsigned int nThread = 0, nTask = 0;
		this->Statistic(nThread, nTask);
		if (m_nMinThread == nThread && 0 == nTask) {
			break;
		}
		else {
			Thread::Sleep(10);
		}

	} while (1);

	TAutoLock lock(m_mtxThread);
	ThreadIterator itr = m_threads.begin();
	while (itr != m_threads.end())
	{
		//!should wait all thread have been done.
		Thread   *pThread = (*itr);
		Runnable *pWorker = pThread->GetRunnable();
		pWorker->Stop();
		pThread->Join();
		delete pThread;
		(*itr) = 0;
		m_threads.erase(itr);
		itr = m_threads.begin();
	}

	//!now, there should be no task.
	assert(m_tasks.empty());
	m_bCreate = false;
}
开发者ID:meanx,项目名称:etl,代码行数:39,代码来源:ThreadPool.cpp

示例12: main

int main ()
{
  printf ("Results of mutex_test:\n");

  try
  {
    LogFilter filter ("system.threads.*", &print_log);

    printf ("create mutex\n");

    Mutex mutex_holder;

    mutex = &mutex_holder;

    printf ("lock mutex\n");

    mutex->Lock ();

    printf ("create thread\n");

    Thread thread (&run);

    while (!flag);

    printf ("unlock mutex\n");

    mutex->Unlock ();

    thread.Join ();

    printf ("exit\n");
  }
  catch (std::exception& exception)
  {
    printf ("exception: %s\n", exception.what ());
  }

  return 0;
}
开发者ID:untgames,项目名称:funner,代码行数:39,代码来源:mutex.cpp

示例13: JoinThread

		void JoinThread() {
			WAWO_ASSERT( m_thread != NULL );
			if(m_thread->Joinable()) {
				m_thread->Join();
			}
		}
开发者ID:ycopy,项目名称:wawo,代码行数:6,代码来源:Thread.hpp

示例14: join

	/// Join timer thread. Wait till exits.
   void join() { _thread.Join(); }
开发者ID:capitalk,项目名称:fix8,代码行数:2,代码来源:timer.hpp


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