Zombie Threads on POSIX systems

前端 未结 2 1606
抹茶落季
抹茶落季 2021-01-13 10:34

How do zombie threads get formed in C/C++, and what do you need to make sure to do in order to prevent them from being created? I know they\'re just normal threads that did

相关标签:
2条回答
  • 2021-01-13 10:59

    A zombie thread is a joinable thread which has terminated, but which hasn't been joined. Normally, either a thread should be joined at some time, or it should be detached. Otherwise, the OS maintains its state for some possible future join, which takes resources.

    0 讨论(0)
  • 2021-01-13 11:15

    Do you mean pthreads or zombie processes? A zombie process (not thread) gets created when a parent doesn't reap its child. It's because the OS keeps the return state of the process if the parent needs it later. If the parent dies, the child is given to the init thread which just sits and calls "wait" over and over again (reaping any children that die). So a zombie process can only be created when the parent is still alive and the child has terminated.

    The same applies for pthreads. If you detach the thread, it will not keep that process termination state around after it finishes (similar to processes).

    0 讨论(0)
提交回复
热议问题