Do child threads exit when the parent thread terminates

后端 未结 3 1550
-上瘾入骨i
-上瘾入骨i 2020-12-01 01:36

I was doing some multithreaded programming in Visual studio C++ using the calls beginthreadex, endthreadex.

I create a child thread thread1. The child thread runs on

3条回答
  •  余生分开走
    2020-12-01 02:04

    As soon as your process die, all the resources are being released (memory, files and threads)

    The correct way to do this: when you call beginthread, keep the returned handle in the parent thread, and call WaitForObject before you leave the program (we join the parent thread with the child thread).

    The parent thread will block until the child thread finish. If your child thread has a infinite loop, you could define an "interruption point" , and check if you should leave. For example, using a shared boolean variable. Check Interrupt Politely fro more info.

提交回复
热议问题