I am a novice in the windows API, and recently I learned I should not use CreateThread and TerminateThread. I switched to _beginthreadex, however I am not sure how I am supposed to use _endthreadex?
For example, here is a basic function I was testing with:
// MyThreadFunction - outputs "#.) I Work" and ends
unsigned int __stdcall MyThreadFunction( void * lpParam )
{
int i = (int)lpParam;
cout << i << ".) I work! " << endl;
_endthreadex(0);
return 0;
}
Is my placement of _endthreadex correct? I have it before the return 0, which just seems odd to me? I read in the msdn pages about _endthreadex that it is called automatically when a function ends, but you should call it for better memory cleanup, and that is why I tried putting it in. It just doesn’t seem right, sorry if this is a bad question. I just want to make sure I am doing everything right to the best of my abilities
You actually don’t need to call
_endthreadex()at all. It will be called for you automatically after your thread function returns anyway.