pthread_detach question

后端 未结 5 1927
鱼传尺愫
鱼传尺愫 2020-12-13 05:12

Till recently, I was under the impression that if you \"detach\" a thread after spawning it, the thread lives even after the \"main\" thread terminates.

But a litt

5条回答
  •  眼角桃花
    2020-12-13 05:34

    To quote the Linux Programmer's Manual:

    The detached attribute merely determines the behavior of the system when the thread terminates; it does not prevent the thread from being terminated if the process terminates using exit(3) (or equivalently, if the main thread returns).

    Also from the Linux Programmer's Manual:

    To allow other threads to continue execution, the main thread should terminate by calling pthread_exit() rather than exit(3).

提交回复
热议问题