#include <iostream> #include <boost/date_time/gregorian/gregorian.hpp> #include <boost/date_time/posix_time/posix_time.hpp> #include <boost/thread.hpp> using namespace boost; using namespace boost::posix_time; void thread_func(); int main(int argc, char** argv) { std::cout << "start at main" << std::endl; /*创建线程对象, 完成后马上执行线程函数的代码*/ thread t(thread_func); /*调用join,让main函数的线程等待线程t的代码执行完返回再继续*/ t.join(); std::cout << "the next step will jump out main()" << std::endl; return 0; } void thread_func() { std::cout << "thread func" << std::endl; /*线程sleep 5秒钟*/ boost::this_thread::sleep(boost::posix_time::seconds(5)); }
原文地址:https://www.cnblogs.com/dilex/p/10474367.html
时间: 2024-10-05 03:10:14