【问题标题】:Can pthread_create() thread-ID of detached thread be ephemeral on the stack? [duplicate]分离线程的 pthread_create() 线程 ID 可以在堆栈上短暂存在吗? [复制]
【发布时间】:2014-06-25 05:11:23
【问题描述】:

如果线程被分离,它是否符合 pthread_create() 函数的线程 ID 参数在堆栈上?例如

void func()
{
    pthread_t thread;
    pthread_create(&thread, NULL, start_func, NULL);
    pthread_detach(thread);
}

或者thread-ID变量的消失会导致问题吗?我已阅读标准,但找不到答案。

【问题讨论】:

  • @this,答案是一样的,但我认为问题的性质不同。
  • @merlin2011 不要害怕Close button
  • @this,我已经关闭了一些真正重复的问题。 :)

标签: c pthreads posix


【解决方案1】:

基于this answer 到一个相关问题,我会说即使您不使用pthread_detach 也是安全的。

由于您将来不会尝试 join 它,因此您没有理由需要保留它。

【讨论】:

    猜你喜欢
    • 2020-07-18
    • 2016-03-02
    • 1970-01-01
    • 2014-07-05
    • 1970-01-01
    • 1970-01-01
    • 2011-10-09
    • 1970-01-01
    • 2021-08-09
    相关资源
    最近更新 更多