posix线程内存消耗

posix thread memory consumption

我有一个 C 程序创建一个分离线程作为 child。 在传递给 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. 每个线程都分配了自己的堆栈。大小是 OS setting dependend,可能在 1M 左右。

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

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