Correct way of checking if threads are done?

前端 未结 6 735
一向
一向 2020-12-18 05:10

I\'m using multithreading in my application with _beginthread and right now to wait until all threads are done I have global bools that get set to true as each thread comple

6条回答
  •  一向
    一向 (楼主)
    2020-12-18 05:48

    Use _beginthreadex instead. Both _beginthread and _beginthreadex return a thread handle, but the thread started with _beginthread automatically closes its handle when it finishes, so using it for synchronization is not reliable.

    Thread handle can be used with one of the synchronization functions of Win32, such as WaitForSingleObject or WaitForMultipleObjects.

    When done, handles returned by _beginthreadex must be closed with CloseHandle().

提交回复
热议问题