thread 学习

Posted wuwangchuxin0924

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了thread 学习相关的知识,希望对你有一定的参考价值。

#include <thread>
#include <cstdio>
#include <utility>
#include <iostream>

void print(int x) {
    printf("%d
", 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 学习的主要内容,如果未能解决你的问题,请参考以下文章

面向面试编程代码片段之GC

python threading超线程使用简单范例的代码

IOS开发-OC学习-常用功能代码片段整理

java SpringRetry学习的代码片段

python 机器学习有用的代码片段

线程操作API