什么是线程退出代码? [英] What is a thread exit code?

查看:171
本文介绍了什么是线程退出代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

调试时输出窗口中的线程退出代码究竟是什么?它给我什么信息?是不是有用或只是内部的东西,不应该打扰我?

 线程0x552c有退出代码259(0x103)。 
线程0x4440已退出代码0(0x0)。

有可能有一些可能的退出代码列表及其含义吗?

解决方案

显然似乎没有很多关于这个问题的解释,但退出代码应该用于给出一个指示线程如何退出, 0 往往意味着它安全退出,而其他任何东西往往意味着它没有按预期退出。但是,这个退出代码可以自己设置,以完全忽略这个。



我可以找到最有用的更多信息的链接是这个



从上面的链接引用:


有什么退出方法,从进程或线程返回的整数必须是值从0-255(8位)。零值表示成功,而非零值表示失败。虽然,您可以尝试返回任何整数值作为退出代码,只有整数的最低字节从进程或线程返回,作为退出代码的一部分。操作系统使用较高阶的字节来传达关于该过程的特殊信息。退出代码在批处理/ shell程序中非常有用,根据一个成功或失败有条件地执行其他程序。







的文档中GetEXitCodeThread


重要GetExitCodeThread函数只有在线程终止后才返回应用程序定义的有效错误代码。因此,应用程序不应使用STILL_ACTIVE(259)作为错误代码。 如果线程作为错误代码返回STILL_ACTIVE(259),那么测试此值的应用程序可以解释为意味着该线程仍在运行,并继续测试该线程在该线程之后的完成已经终止,这可能使应用程序进入无限循环。







我的理解所有这一切,如果您在自己的应用程序中使用线程您自己的应用程序,退出代码并不重要。这个例外是可能的,如果你在同一时间运行几个线程相互依赖。如果需要外部来源阅读此错误代码,那么您可以将其设置为让其他应用程序知道您的线程的状态。


What exactly is a thread exit code in the Output window while debugging? What information it gives me? Is it somehow useful or just an internal stuff which should not bother me?

The thread 0x552c has exited with code 259 (0x103).
The thread 0x4440 has exited with code 0 (0x0).

Is there maybe some sort of list of possible exit codes along with its significance?

解决方案

There actually doesn't seem to be a lot of explanation on this subject apparently but the exit codes are supposed to be used to give an indication on how the thread exited, 0 tends to mean that it exited safely whilst anything else tends to mean it didn't exit as expected. But then this exit code can be set in code by yourself to completely overlook this.

The closest link I could find to be useful for more information is this

Quote from above link:

What ever the method of exiting, the integer that you return from your process or thread must be values from 0-255(8bits). A zero value indicates success, while a non zero value indicates failure. Although, you can attempt to return any integer value as an exit code, only the lowest byte of the integer is returned from your process or thread as part of an exit code. The higher order bytes are used by the operating system to convey special information about the process. The exit code is very useful in batch/shell programs which conditionally execute other programs depending on the success or failure of one.


From the Documentation for GetEXitCodeThread

Important The GetExitCodeThread function returns a valid error code defined by the application only after the thread terminates. Therefore, an application should not use STILL_ACTIVE (259) as an error code. If a thread returns STILL_ACTIVE (259) as an error code, applications that test for this value could interpret it to mean that the thread is still running and continue to test for the completion of the thread after the thread has terminated, which could put the application into an infinite loop.


My understanding of all this is that the exit code doesn't matter all that much if you are using threads within your own application for your own application. The exception to this is possibly if you are running a couple of threads at the same time that have a dependency on each other. If there is a requirement for an outside source to read this error code, then you can set it to let other applications know the status of your thread.

这篇关于什么是线程退出代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆