2

There's this function on _beginthreadex MSDN page:

unsigned __stdcall SecondThreadFunc( void* pArguments )
{
    printf( "In second thread...\n" );

    while ( Counter < 1000000 )
    Counter++;

    _endthreadex( 0 );
    return 0;
}

I know you can get the value returned by _endthreadex with the function GetExitCodeThread, but how do you get the value returned by return?

Another question: doesn't _endthreadex end the thread, why did they put a return 0 after that?

c00get
  • 23
  • 3

2 Answers2

1

In this snippet the return statement is indeed only to make the compiler happy. However, in fact, you don't need to call _endthreadex as it is called internally by _beginthreadex after you return from your thread function. And it passes your return value to _endthreadex (or ExitThread, from it).

See Raymond Chen's article

Yogurt
  • 83
  • 9
0

return 0 is there just to make the compiler happy. _endthreadex does not return.

atzz
  • 17,507
  • 3
  • 35
  • 35