【发布时间】:2015-04-23 05:12:08
【问题描述】:
当我像这样使用std::thread 时:
func()
{
std::thread(std::bind(&foo, this));
}
线程对象在堆栈中分配,并在func() 返回时被销毁。
所以我尝试像这样使用它:
func()
{
std::thread* threadPtr = new std::thread(std::bind(&foo, this));
}
我应该在哪里delete threadPtr?
以及如何创建一个最初被挂起的线程?
【问题讨论】:
-
"我应该在哪里删除 threadPtr?" 这取决于你,但你没有句柄可以在函数内部以外的任何地方删除它。
-
您实际上想要完成什么?如果您告诉我们您要解决的具体问题,我们或许可以为您提供更好的建议。
标签: c++ multithreading stdthread