本文整理汇总了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());
}
示例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;
}
示例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);
}
示例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"));
}
示例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();
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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
}
示例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;
}
示例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;
}
示例13: JoinThread
void JoinThread() {
WAWO_ASSERT( m_thread != NULL );
if(m_thread->Joinable()) {
m_thread->Join();
}
}
示例14: join
/// Join timer thread. Wait till exits.
void join() { _thread.Join(); }