首页 > 其他 > 详细

thread 学习

时间:2019-01-06 23:43:47      阅读:190      评论:0      收藏:0      [点我收藏+]
#include <thread>
#include <cstdio>
#include <utility>
#include <iostream>

void print(int x) {
    printf("%d\n", x);
}

int main() {
    std::thread t1(print, 1);
    std::thread t2(print, 2);

    // 获得线程ID
    std::thread::id t1_id = t1.get_id();
    std::thread::id t2_id = t2.get_id();
    std::cout << t1_id << " " << t2_id << std::endl;    
    
    /* 
     * 阻塞当前线程,直至 *this 所标识的线程完成其执行。
     * *this 所标识的线程的完成同步于从 join() 的成功返回。
     */
    t1.join();
    t2.join();
    return 0;
}

 

thread 学习

原文:https://www.cnblogs.com/wuwangchuxin0924/p/10230851.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!