如果删除其参数,另一个线程中的 std::thread 是否会崩溃?

Does std::thread in another thread crash if its parameters are deleted?

我读了很多,但我仍然不确定我是否理解它(我是一名木工)。

假设我有一个函数:

void class_test::example_1(int a, int b, char c)
{
//do stuff
int v;
int k;
char z;
if(condition)
    {
     std::thread thread_in_example (&class_test::example_1, & object, v ,k ,z);
     th.detach();
    }
}

现在如果我调用它:

std::thread example (&class_test::example_1, &object, a, b, c);
example.detach();

问题:当示例[=36时,thread_in_example会发生什么=]完成&"detele"他自己? thread_in_example 会失去对其参数的访问权限吗?

我认为 std::thread 正在制作元素的副本,除非它们是由 &reference 给出的,但是在 http://en.cppreference.com/w/cpp/thread/thread 我无法真正理解这部分(由于我缺乏 programming/english/computer 科学的语义):

std::thread objects may also be in the state that does not represent any thread (after default construction, move from, detach, or join), and a thread of execution may be not associated with any thread objects (after detach).

还有这个:

No two std::thread objects may represent the same thread of execution; std::thread is not CopyConstructible or CopyAssignable, although it is MoveConstructible and MoveAssignable.

所以我怀疑它到底是如何工作的。

来自this std::thread::detach reference

Separates the thread of execution from the thread object, allowing execution to continue independently. Any allocated resources will be freed once the thread exits.

[强调我的]

其中 "allocated resources" 将是参数,这意味着您仍然可以安全地在分离线程中使用参数。

当然,除非您的参数是对对象的引用或指针,这些对象独立于分离线程或创建分离线程的线程被破坏。