int main() { // Create module module1 = new ContinuousControlManager("ContinuousControl:Manager"); //Dummy test interface //dummyIface = new ContinuousControlInterface("DummyIface"); // Debug DEBUG(LEVEL_INFO, "Created!"); // Connect //dummyIface->q_out_ = &module1->interface->q_in; //module1->interface->q_out_ = &dummyIface->q_in; // Run module boost::thread th1( boost::bind( &ContinuousControlManager::Run, module1) ); boost::thread th2( testThread ) ; // Wait for threads to end th1.join(); th2.join(); return 0; }
int main (int argc, char**argv) { std::cout << "\nwithout lock:\n"; std::thread th1 (print_block,50,'*'); std::thread th2 (print_block,50,'$'); th1.join(); th2.join(); std::cout << "\nwith unique_lock:\n"; std::thread th3 (print_block_lock_guard,50,'*'); std::thread th4 (print_block_lock_guard,50,'$'); th3.join(); th4.join(); std::cout << "\nwith lock_guard:\n"; std::thread th5 (print_block_unique_lock,50,'*'); std::thread th6 (print_block_unique_lock,50,'$'); th5.join(); th6.join(); return 0; }
int main(){ boost::thread th1(boost::bind(&push, 0)), th2(pop); th1.join(); th2.join(); return 1; }
int main() { try { boost::barrier tb( 2); boost::fibers::spin::barrier fb( 2); std::cout << "start" << std::endl; boost::thread th1( boost::bind( & f, boost::ref( tb), boost::ref( fb) ) ); boost::thread th2( boost::bind( & g, boost::ref( tb), boost::ref( fb) ) ); th1.join(); th2.join(); std::cout << "finish" << std::endl; return EXIT_SUCCESS; } catch ( boost::system::system_error const& e) { std::cerr << "system_error: " << e.code().value() << std::endl; } catch ( boost::fibers::scheduler_error const& e) { std::cerr << "scheduler_error: " << e.what() << std::endl; } catch ( std::exception const& e) { std::cerr << "exception: " << e.what() << std::endl; } catch (...) { std::cerr << "unhandled exception" << std::endl; } return EXIT_FAILURE; }
void testThread() { char arg1[] = "th1"; char arg2[] = "th2"; Thread th1((Thread::Routine)foo, arg1); Thread th2((Thread::Routine)foo, arg2); th1.setBackground(true); th1.start(); th2.start(); #ifdef _WIN32 Thread::sleep(500); th1.suspend(); LOGT("th1 was suspended."); Thread::sleep(500); th2.suspend(); LOGT("th2 was suspended."); Thread::sleep(500); th1.resume(); LOGT("th1 was resumed."); Thread::sleep(500); th2.resume(); LOGT("th2 was resumed."); #endif int ret2 = th2.join(); LOG_VAR(ret2); }
void function() { SmartPtr<Derived> myObj = new Derived(); Dummy th1(myObj); // Doesn't work under Cygnus Dummy th2((Base0 *) myObj); // Doesn't work either }
int main(){ std::thread th1(print_foo); std::thread th2(set_foo, 10); th1.join(); th2.join(); return 0; }
int main() { std::thread th1(print_block, 50, '*'); std::thread th2(print_block, 50, '$'); th1.join(); th2.join(); return 0; }
int main() { queue<int> q; std::thread th1(push,&q); std::thread th2(pop,&q); th1.join(); th2.join(); return 0; }
int main() { std::thread th1([]{ rnd_fkt(1); }); std::thread th2([]{ rnd_fkt(2); }); th1.join(); th2.join(); return 0; }
int main () { Hx::thread th1 (task_a); Hx::thread th2 (task_b); th1.join(); th2.join(); return 0; }
void testCondition() { Thread th1((Thread::Routine)changer); Thread th2((Thread::Routine)watcher); th1.start(); th2.start(); th1.join(); th2.join(); }
FileSystem::FileSystem(int port, Membership& m) : membership(m), port(port) { logFile.open("logFileSystem.log"); // we can make all the logs going to a single file, but nah. std::thread th2(&FileSystem::updateThread, this); ringUpdating.swap(th2); std::thread th1(&FileSystem::listeningThread, this); listening.swap(th1); }
int main() { { std::thread th1(print_block, 40, '*'); std::thread th2(print_block, 40, '$'); th1.join(); th2.join(); } std::cout << "=== next run ===========================+\n"; { std::thread th1(print_critial_block, 40, '*'); std::thread th2(print_critial_block, 40, '$'); th1.join(); th2.join(); } return 0; }
int main(){ boost::mutex mutex; Task task1(1, &mutex); Task task2(2, &mutex); boost::thread th1(&Task::run, &task1); boost::thread th2(&Task::run, &task2); th1.join(); th2.join(); return 0; }
int main(int argc, char** argv) { int a = 0; spinlock spin; std::thread th1(th_write, std::ref(spin), std::ref(a)); std::thread th2(th_read, std::ref(spin), std::ref(a)); th1.join(); th2.join(); return 0; }
int main(int argc, char** argv) { std::thread th1(print_this); std::thread th2(print_this); std::thread th3(print_this); std::thread th4(print_this); th1.join(); th2.join(); th3.join(); th4.join(); return 0; }
int main() { cv = new std::condition_variable_any; std::thread th2(g); m.lock(); while (!g_ready) cv->wait(m); m.unlock(); std::thread th1(f); th1.join(); th2.join(); }
int main() { std::thread th1(print_block, 20, '*'); std::thread th2(print_block, 20, '#'); std::thread th3(print_block, 20, 'a'); std::thread th4(print_block, 20, '&'); th1.join(); th2.join(); th3.join(); th4.join(); return 0; }
main() { float a,b,c,d,e,f; printf("\nNhap vao a,b,c,d,e,f : "); scanf("%f %f %f %f %f %f",&a,&b,&c,&d,&e,&f); dd = a*e - d*b; dx = b*f - e*c; dy = a*f - d*c; if (dd != 0) th1(); else if ((dx == dy)&&(dy == 0)) th2(); else th3(); getch(); }
void testObj::test<3>(void) { double data[2]={1, 2}; Mutex mutex; TestLocker tl1(&mutex, data); TestLocker tl2(&mutex, data); // start two threads Base::Threads::ThreadJoiner th1(tl1); Base::Threads::ThreadJoiner th2(tl2); // and join them th1->join(); th2->join(); }
CosmosQueue::CosmosQueue(unsigned int port, unsigned int sendSize, unsigned int recvSize): cosmos(port), tlmQueue(), cmdQueue() { connected.store(false); tlmCapacity = sendSize; cmdCapacity = recvSize; if (tlmCapacity > 0) { std::thread th1(&CosmosQueue::tlm_thread, this); th1.detach(); } if (cmdCapacity > 0) { std::thread th2(&CosmosQueue::cmd_thread, this); th2.detach(); } }
int main(int, char**) { cv = new std::condition_variable; std::thread th2(g); Lock lk(m); while (!g_ready) cv->wait(lk); lk.unlock(); std::thread th1(f); th1.join(); th2.join(); return 0; }
int main(){ boost::thread th1(boost::bind(&insert, 0)), th2(boost::bind(&insert, 1)); th1.join(); th2.join(); for(int i = 0; i < 2; i++){ for(int j = 0; j < 10000; j++){ std::string str; table.search(j+(i*10000), str); std::cout << str << std::endl; } } return 1; }
int main() { cv = new boost::permit_c_any; boost::thread th2(g); Lock lk(m); while (!g_ready) { cv->wait(lk); } lk.unlock(); boost::thread th1(f); th1.join(); th2.join(); return boost::report_errors(); }
int main() { cv = new boost::condition_variable; boost::thread th2(g); Lock lk(m); while (!g_ready) { cv->wait(lk); } lk.unlock(); boost::thread th1(f); th1.join(); th2.join(); return boost::report_errors(); }
int main() { std::thread th1(do_work); std::thread th2(do_work); std::thread th3(do_work); std::thread th4(do_work); std::thread th5(do_work); th1.join(); th2.join(); th3.join(); th4.join(); th5.join(); std::cout << "Result:" << data << '\n'; }
//Multi-thread with on io_service instance and serval handler threads. void test_2() { boost::asio::io_service service; boost::asio::deadline_timer t1(service, boost::posix_time::seconds(5)); t1.async_wait(boost::bind(handler, "timer1", _1)); boost::asio::deadline_timer t2(service, boost::posix_time::seconds(5)); t2.async_wait(boost::bind(handler, "timer2", _1)); boost::asio::deadline_timer t3(service, boost::posix_time::seconds(5)); t3.async_wait(boost::bind(handler, "timer3", _1)); boost::asio::deadline_timer t4(service, boost::posix_time::seconds(5)); t4.async_wait(boost::bind(handler, "timer4", _1)); boost::thread th1([&service]() { service.run(); }); boost::thread th2([&service]() { service.run(); }); th1.join(); th2.join(); }
int main(void) { //exemodel::mask_signal(SIGUSR1); /*start fusion splice service*/ std::unique_ptr<thread_test> fs_svr(new thread_test()); std::thread th1([&fs_svr](void){ exemodel::mask_signal(SIGUSR1); fs_svr->run(); }); /*start heat service*/ std::unique_ptr<thread_test> heat_svr(new thread_test()); std::thread th2([&heat_svr](void){ exemodel::mask_signal(SIGUSR1); heat_svr->run(); }); /*start device manage service*/ std::unique_ptr<thread_test> devmng_svr(new thread_test()); std::thread th3([&devmng_svr](void){ exemodel::mask_signal(SIGUSR1); devmng_svr->run(); }); s_sigterm_hdl = [&th1, &th2, &th3](void) { std::cout << "start send sigusr1" << std::endl; ::pthread_kill(th1.native_handle(), SIGUSR1); ::pthread_kill(th2.native_handle(), SIGUSR1); ::pthread_kill(th3.native_handle(), SIGUSR1); std::cout << "stop send sigusr1" << std::endl; }; //exemodel::mask_signal(SIGTERM); std::signal(SIGINT, signal_handler); std::cout << "start wait" << std::endl; th1.join(); std::cout << "start wait1" << std::endl; th2.join(); std::cout << "start wait2" << std::endl; th3.join(); std::cout << "start wait3" << std::endl; return 0; }
int main(void) { std::thread th1(Encode) ; sleep(1) ; std::thread th2(Decode) ; th1.join() ; th2.join() ; //statistic here std::fstream c("correct.txt", std::ios::in) ; std::fstream d("decoded.txt", std::ios::in) ; std::fstream rp("report.txt", std::ios::out | std::ios::trunc) ; int cnt = 0 ; std::vector<char> ans ; for(int n=0;n<maxN;n++) { char tmp ; c >> tmp ; ans.push_back(tmp) ; } for(int n=0;n<maxN;n++) { int mycnt = 0 ; bool good = true ; for(int i=0;i<=n;i++) { char tmp ; d >> tmp ; if(good && ans[i]==tmp) mycnt++ ; else good = false ; } rp << n+1 << ", " << mycnt << std::endl ; cnt = mycnt ; } printf("We decoded %d prefix correctly.\n", cnt) ; c.close() ; d.close() ; rp.close() ; return 0 ; }