pthread_detach question

后端 未结 5 1938
鱼传尺愫
鱼传尺愫 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:47

    Yes, the detached threads will die after return 0.

    From the NOTES section of man pthread_detach

    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 equiv‐alently, if the main thread returns)

提交回复
热议问题