多线程 问题整理

    技术2024-11-03  57

    线程是并发 不是并行的
    线程创建方式的好多种方式

    1.thread ● 函数

    thread t1(fun,1);

    ● lamda 函数

    thread t2([](){},2);

    ● 类对象

    Solution s; thread t3(s,3); //传递 s 的拷贝对象给子线程 thread t4(ref(s),4); //传递 s 的引用给子线程 thread t5(move(s),5); //移动 s 对象给子线程,主线程不再有效 thread t6(Solution(),6);

    2.async as


    join 和 detach
    unique_lock 和 lock_guard
    sleep for 和wait
    condition_variable
    Processed: 0.014, SQL: 9