The following sample code demonstrates how you can use the thread
handle returned by _beginthreadex with the synchronization API
WaitForSingleObject. The
main thread waits for the second thread to terminate before it continues. When
the second thread calls _endthreadex, it causes its thread object to go
to the signaled state. This allows the primary thread to continue running. This
cannot be done with _beginthread and _endthread, because
_endthread calls CloseHandle, destroying the thread object before
it can be set to the signaled state.