int main(int argc, char** argv) { std::thread thread1(run_master); std::thread thread2(run_watcher); thread1.join(); thread2.join(); return 0; }
void main() { x = 0; y = 0; thread1(); thread2(); thread3(); }
void testThreadInitAndExit() { std::cout<<"****** Running thread start and delete test ****** "<<std::endl; { MyThread thread; thread.startThread(); } // add a sleep to allow the thread start to fall over it its going to. OpenThreads::Thread::microSleep(500000); std::cout<<"pass thread start and delete test"<<std::endl<<std::endl; std::cout<<"****** Running notify thread test ****** "<<std::endl; { NotifyThread thread1(osg::INFO,"thread one:"); NotifyThread thread2(osg::INFO,"thread two:"); NotifyThread thread3(osg::INFO,"thread three:"); NotifyThread thread4(osg::INFO,"thread four:"); thread1.startThread(); thread2.startThread(); thread3.startThread(); thread4.startThread(); // add a sleep to allow the thread start to fall over it its going to. OpenThreads::Thread::microSleep(5000000); } std::cout<<"pass noitfy thread test."<<std::endl<<std::endl; }
int main(int ac, char* av[]) { LOG_MSG << "LogTestApp. -- written by Wilston Oreo."; #ifdef TEST_THREADS srand ( time(NULL) ); LOG_MSG_(1) << "Startup"; boost::thread thread1(threadLog); boost::thread thread2(threadLog); boost::thread thread3(threadLog); boost::thread thread4(threadLog); LOG_MSG_(1) << "Waiting for threads..."; thread1.join(); thread2.join(); thread3.join(); thread4.join(); #endif LOG_MSG_(1) << "Done"; LOG->level(2); LOG_MSG_(1) << fmt("Log level: %") % LOG->level(); LOG_WRN << fmt("Warning %") % 3; LOG_MSG_(3); LOG_MSG_(4); LOG_ERR << "ERROR"; return 0; }
int main() { std::cout << "Starting" << std::endl; // 1 - lock the mutex boost::shared_lock<boost::shared_mutex> lock (mutex); // 2 - start thread#2 boost::thread thread2(&thread2_func); // 3 - sleep boost::this_thread::sleep(boost::posix_time::milliseconds(10)); std::cout << "Thread#2 is waiting" << std::endl; // - start thread3 boost::thread thread3(&thread3_func); //boost::thread thread3(&thread3_func_workaround); std::cout << "Thread#3 is started and blocked. It never will waked" << std::endl; thread3.join(); // will never return lock.unlock(); // release shared ownership. thread#2 will take unique ownership thread2.join(); std::cout << "Finished" << std::endl; return 0; }
void main() { starting = 1; IntrMask = 0; patched = 0; thread1(); thread2(); }
main() { IntrMask = 0; intr_mask = 0; handled = 0; thread1(); thread2(); }
int main () { printf ("Results of cancel_thread_test:\n"); try { LogFilter filter ("system.threads.*", &print_log); Thread thread1 (&thread1_run), thread2 (&thread2_run); thread [0] = &thread1; thread [1] = &thread2; int result1 = thread [1]->Join (), result0 = thread [0]->Join (); printf ("join thread2: %d\n", result1); printf ("join thread1: %d\n", result0); fflush (stdout); } catch (std::exception& exception) { printf ("exception: %s\n", exception.what ()); } return 0; }
static void t2(void* a, void* b) { (void) a; (void) b; thread2(); lwt_sig_signal(sig); }
int main() { std::mutex m; std::condition_variable cond_var; std::thread thread1([&m, &cond_var](){ for(;;) { std::this_thread::sleep_for(std::chrono::seconds(1)); std::unique_lock<std::mutex> lock(m); std::cout << "first" << std::endl; cond_var.notify_one(); } }); std::thread thread2([&m, &cond_var](){ for(;;) { std::unique_lock<std::mutex> lock(m); cond_var.wait(lock); std::cout << "second" << std::endl; } }); thread1.join(); thread2.join(); return 0; }
//-***************************************************************************** int main( int argc, char* argv[] ) { boost::thread thread1( &test ); boost::thread thread2( &test ); thread1.join(); thread2.join(); return 0; }
int main() { __CPROVER_ASYNC_1: thread1(); __CPROVER_ASYNC_1: thread2(); __CPROVER_ASYNC_1: thread3(); __CPROVER_assume(y==3); assert(x!=1); return 0; }
void PresetTests::parallelAccessTest() { const int initIterations = 100; const int itemsToGenerate = 5; DECLARE_MODELS_AND_GENERATE(itemsToGenerate); QString presetName = "preset"; QStringList keywords; keywords << "keyword1" << "another keyword" << "test"; Helpers::Barrier barrier1(2), barrier2(2); bool isAdded1, isAdded2; volatile bool removed1; volatile bool removed2; KeywordsPresets::ID_t id1 = 0; KeywordsPresets::ID_t id2 = 0; std::thread thread1([&]() { int n = initIterations; while (n--) { isAdded1 = false; id1 = 0; presetKeywordsModel.addOrUpdatePreset(presetName, keywords, id1, isAdded1); /*-------------*/barrier1.wait(); Q_ASSERT(isAdded1 != isAdded2); Q_ASSERT(id1 == id2); removed1 = presetKeywordsModel.removePresetByID(id1); /*-------------*/barrier2.wait(); Q_ASSERT(removed1 != removed2); } }); std::thread thread2([&]() { int n = initIterations; while (n--) { isAdded2 = false; id2 = 1; presetKeywordsModel.addOrUpdatePreset(presetName, keywords, id2, isAdded2); /*-------------*/barrier1.wait(); Q_ASSERT(isAdded1 != isAdded2); Q_ASSERT(id1 == id2); removed2 = presetKeywordsModel.removePresetByID(id2); /*-------------*/barrier2.wait(); Q_ASSERT(removed1 != removed2); } }); thread1.join(); thread2.join(); }
void testThreads() { Thread thread1(1); Thread thread2(2); thread1.start(); thread2.start(); thread1.wait(); thread2.wait(); }
void main() { registered = 0; initialised1 = 0; initialised2 = 0; initialised3 = 0; thread1(); thread2(); thread3(); }
void main() { while(1) { thread1(); thread2(); if(exit==0) break; } }
int main() { std::thread thread1(function_modifying_global_struct, 1); std::thread thread2(function_modifying_global_struct, 2); thread1.join(); thread2.join(); return 0; }
void main() { for(int i = 0; i < 10; i++) { boost::thread thread1(boost::bind(&func1)); boost::thread thread2(boost::bind(&func2)); thread2.join(); thread1.join(); } }
void main() { napi_poll = 0; shutdown = 0; stuff1_done = 0; updated = 0; napi_disabled = 0; thread1(); thread2(); thread3(); }
int main () { std::thread thread1(task1); std::thread thread2(task2); thread1.join(); thread2.join(); return EXIT_SUCCESS; }
void main() { data = 0; mutex = 0; thread1(); thread2(); thread3(); }
int main() { boost::thread thread1(boost::bind(func, "tom", 160)); boost::thread thread2(boost::bind(func, "glen", 500)); sleep(3); thread1.join(); thread2.join(); return 0; }
int main(int argc, char **argv) { Aria::init(Aria::SIGHANDLE_THREAD, false); ArMutex mutex; mutex.setLogName("mutex"); ArMutex::setLockWarningTime(1); ArMutex::setUnlockWarningTime(5); TestThread thread1(1, mutex), thread2(2, mutex), thread3(3, mutex), thread4(4, mutex); thread1.setThreadName("thread1"); thread2.setThreadName("thread2"); thread3.setThreadName("thread3"); thread4.setThreadName("thread4"); srand(time(0)); thread1.create(); thread2.create(); thread3.create(); printf("main thread name=\"%s\", OS handle=%lu, OS pointer=0x%x\n", ArThread::getThisThreadName(), ArThread::getThisOSThread(), (unsigned int) ArThread::getThisThread()); printf("thread1 thread name=\"%s\", OS handle=%lu, OS pointer=0x%x\n", thread1.getThreadName(), thread1.getOSThread(), (unsigned int) thread1.getThread()); printf("thread2 thread name=\"%s\", OS handle=%lu, OS pointer=0x%x\n", thread2.getThreadName(), thread2.getOSThread(), (unsigned int) thread2.getThread()); printf("thread3 thread name=\"%s\", OS handle=%lu, OS pointer=0x%x\n", thread3.getThreadName(), thread3.getOSThread(), (unsigned int) thread3.getThread()); printf("thread4 (not created yet) thread name=\"%s\", OS handle=%lu, OS pointer=0x%x\n", thread4.getThreadName(), thread4.getOSThread(), (unsigned int) thread4.getThread()); if(ArThread::getThisOSThread() == thread1.getOSThread() || ArThread::getThisOSThread() == thread2.getOSThread() || ArThread::getThisOSThread() == thread3.getOSThread() || ArThread::getThisOSThread() == thread4.getOSThread() || thread1.getOSThread() == thread2.getOSThread() || thread1.getOSThread() == thread3.getOSThread() || thread1.getOSThread() == thread4.getOSThread() || thread2.getOSThread() == thread1.getOSThread() || thread2.getOSThread() == thread3.getOSThread() || thread2.getOSThread() == thread4.getOSThread() || thread3.getOSThread() == thread1.getOSThread() || thread3.getOSThread() == thread2.getOSThread() || thread3.getOSThread() == thread4.getOSThread() || thread4.getOSThread() == thread1.getOSThread() || thread4.getOSThread() == thread2.getOSThread() || thread4.getOSThread() == thread3.getOSThread() ) { puts("error, some thread IDs are the same!"); return 5; } thread4.runInThisThread(); Aria::shutdown(); return(0); }
int main() { A object ; std::thread thread( &A::foo /* function */ , &object /* this */, 1234 /* arg */ ) ; thread.join() ; // object is moved to the thread std::thread thread2( &A::foo, std::move(object), 5678 ) ; thread2.join() ; }
void main() { x = 0; y = 0; z = 0; a = 0; b = 0; thread1(); thread2(); thread3(); thread4(); }
int main() { mystack<std::function<bool()>> stk; // une version sans pointeurs serait meilleure/plus simple int n = 10; std::thread thread1(fun1, std::ref(stk), std::ref(n)); std::thread thread2(fun2, std::ref(stk)); thread1.join(); thread2.join(); std::cout << "Fin." << std::endl; return 0; }
int main(){ Worker w1 {5}; std::thread thread1(w1); thread_guard tg1(thread1); Worker w2 {7}; std::thread thread2(w2); thread_guard tg2(thread2); Worker w3 {9}; std::thread thread3(w3); thread_guard tg3(thread3); return 0; }
void testMutilQueue(int testSize ) { BlockingQueue<string> t_queue(testSize); char* c_str = new char[1024]; memset(c_str, 0, 1024); string msg(c_str); QueueThread thread1(t_queue,true,testSize,&msg); QueueThread thread2(t_queue,false,testSize,NULL); thread1.start(); thread2.start(); sleep(100); delete[] c_str; }
bool ServiceLocator::test() { bool result = true; int n = 0; ServiceLocator* loc = ServiceLocator::getDefaultLocator(); std::thread thread1(testThread, ++n, loc); std::thread thread2(testThread, ++n, loc); thread1.join(); thread2.join(); return result; }
int main() { // Crear algunos hilos independientes cada uno de los cuales // ejecutará increment_counter() std::thread thread1(increment_counter); std::thread thread2(increment_counter); // Esperar a que los hilos terminen antes de que main() continúe. // Si no esperamos, corremos el riesgo de terminar el proceso y todos // sus hilos antes de que los hilos hayan terminado. thread1.join(); thread2.join(); std::cout << "Valor final del contador: " << counter << "\n"; return 0; }