Merl
Merl

Reputation: 96

posix thread memory consumption

I have a C program creating a detached thread as a child. Inside of the function I pass to pthread_create I use pthread_detach to detach the thread. At the end I call pthread_exit((void *) 0)

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

I did a valgrind check and there are no leaks just 4 suppressed errors.

Upvotes: 0

Views: 264

Answers (1)

alk
alk

Reputation: 70979

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

Yes, as

  1. each thread gets its own stack assigned. The size is OS setting dependend and could be around 1M.

  2. some system resource will be used to manage each thread itself.

Both will be released if the thread ends for a detached thread or if the thread was joined for a joinable thread.

Upvotes: 0

Related Questions