The answer is already indicated in the short version, and if you are interested in learning more, returning from your function will actually be used as an argument in the _endthreadex call. Here's what happens at runtime when starting a thread. The thread really starts from the starting point somewhere in the CRT, where the internal _callthreadstartex :
_endthreadex(MyThreadFunction(...));
That is, as soon as you return, _endthreadex will be immediately called for you, and it will exit the stream.
Can you use it explicitly? Yes, you can, and your code is also good, because it does not matter whether you call it yourself or it will be called for you, provided that there are no leaks on the way (for example, in particular, local variables not yet named by destructors).
Since it will be called for you in any case, and returning from the function is safer from the point of view of freeing local resources, there is no benefit, advantage and sense for an explicit call.
MSDN basically explains exactly the same in the Remarks section.
You can explicitly call _endthread or _endthreadex to complete the thread; however, _endthread or _endthreadex is called automatically when the thread returns from the procedure passed as a parameter to _beginthread or _beginthreadex. Terminating a thread with an endthread or _endthreadex call helps ensure proper recovery of resources allocated to the thread.
Roman R.
source share