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

标签 c++ multithreading oop heap-memory

有没有一种方法可以使用“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();
}

关于c++ - 如何在堆上初始化线程? (使用 “new”关键字),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59081712/

相关文章:

java - 使用大多数 Java 代码制作可执行文件,但可能会添加另一种语言

c++ - 使用宏声明运算符

c# - 填充同一 DataSet 的不同 DataTable 是线程安全操作吗?

c# - ASP.NET Core线程中默认的IServiceProvider安全吗?

c++ - 如何在项目的各个部分之间创建松散耦合?

javascript - 如何专门化一个 Javascript 类?

c# - 将 C++ 函数转换为 C#(字符串问题)

c++ - 'Windows.h : No such file or directory"error when changing Platform Toolset to v140_xp

multithreading - Spring @Controller 生命周期

php - 将 MySQL 链接传递给类方法