gpt4 book ai didi

c - pthread_join 中的悬垂指针?

转载 作者:太空宇宙 更新时间:2023-11-03 23:53:13 24 4
gpt4 key购买 nike

根据 this ,pthread_join设置输出参数**thread_return为pd->result,然后释放pd。这样可以吗,我遗漏了什么,还是 glibc 中存在严重错误?

    /* We mark the thread as terminated and as joined.  */
pd->tid = -1;

/* Store the return value if the caller is interested. */
if (thread_return != NULL)
*thread_return = pd->result;


/* Free the TCB. */
__free_tcb (pd);

最佳答案

__free_tbc 不释放 pd,而是释放线程的堆栈,即 pd->tpp(另见 here)。所以 pd->result 在这些语句之后仍然是一个有效的指针。

关于c - pthread_join 中的悬垂指针?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14547891/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com