你如何在堆上初始化一个线程? (使用 "new" 关键字)
How do you initialize a thread on the heap? (Using the "new" keyword)
有没有办法使用 "new" 关键字在堆上初始化一个 std::thread
?
不要用new,用make_unique
沿着这条线的东西:
#include<thread>
#include<memory>
bool fun1()
{
return true;
}
int main() {
auto thread1 = std::make_unique<std::thread>( fun1 );
thread1->join();
}
有没有办法使用 "new" 关键字在堆上初始化一个 std::thread
?
不要用new,用make_unique
沿着这条线的东西:
#include<thread>
#include<memory>
bool fun1()
{
return true;
}
int main() {
auto thread1 = std::make_unique<std::thread>( fun1 );
thread1->join();
}