您如何在堆上初始化线程? (使用“ new”关键字)

问题描述 投票:0回答:1

是否有使用“ new”关键字在堆上初始化std::thread的方法?

c++ multithreading oop heap-memory
1个回答
0
投票

不要使用新的,请使用make_unique

沿着这条线的东西:

#include<thread>
#include<memory>

bool fun1()
{
    return true;
}

int main() {
    auto thread1 = std::make_unique<std::thread>( fun1 );


    thread1->join();
}
© www.soinside.com 2019 - 2024. All rights reserved.