zoukankan      html  css  js  c++  java
  • boost::thread demo

    #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));
    }
    
  • 相关阅读:
    Java实现2048小游戏
    归并排序【代码】
    插入排序【代码】
    选择排序【代码】
    考试系统
    九九乘法表
    万年历
    猜数游戏
    C++知识点(杂)
    Core Data ,inverse
  • 原文地址:https://www.cnblogs.com/dilex/p/10474367.html
Copyright © 2011-2022 走看看