gpt4 book ai didi

c - posix线程内存消耗

转载 作者:行者123 更新时间:2023-11-30 17:12:33 25 4
gpt4 key购买 nike

我有一个 C 程序,它创建一个分离线程作为子线程。在我传递给 pthread_create 的函数内部,我使用 pthread_detach 来分离线程。最后我调用 pthread_exit((void *) 0)

我想知道线程创建后内存消耗增加是否正常。

我做了 valgrind 检查,没有泄漏,只有 4 个被抑制的错误。

最佳答案

I would like to know if it is normal behaviour that the memory consumption increases after the thread is created.

是的,如

  1. 每个线程都分配有自己的堆栈。大小取决于操作系统设置,可能约为 1M。

  2. 一些系统资源将用于管理每个线程本身。

如果分离线程的线程结束或可连接线程的线程连接,两者都会被释放。

关于c - posix线程内存消耗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31463839/

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