了解MSDN _beginthreadex函数示例
_beginthreadex
MSDN 上有此函数page:
unsigned __stdcall SecondThreadFunc( void* pArguments )
{
printf( "In second thread...\n" );
while ( Counter < 1000000 )
Counter++;
_endthreadex( 0 );
return 0;
}
我知道可以用函数GetExitCodeThread
获取_endthreadex
返回的值,但是如何获取return
返回的值代码>?
另一个问题:_endthreadex
不是结束线程吗,为什么他们在后面放了一个return 0
?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在此代码片段中,
return
语句确实只是为了让编译器满意。然而,事实上,您不需要调用_endthreadex
,因为它是在您从线程函数返回后由_beginthreadex
在内部调用的。它将您的返回值传递给_endthreadex
(或从中传递给ExitThread
)。请参阅Raymond Chen 的文章
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
(orExitThread
, from it).See Raymond Chen's article
return 0
只是为了让编译器满意。_endthreadex
不返回。return 0
is there just to make the compiler happy._endthreadex
does not return.