Question about thread exit code and thread handle value

本文探讨了在多线程应用程序中如何理解线程ID和退出状态码的意义。特别是针对不同退出状态码所代表的应用程序运行情况进行了详细的解释,并讨论了如何通过线程ID来跟踪特定线程的状态。

 

http://msdn.microsoft.com/en-us/library/ms682659(VS.85).aspx

http://social.msdn.microsoft.com/forums/en-US/vsdebug/thread/1d92fc36-3e42-4057-abbc-f162bdd226ac/

 

I believe anyone will see info in debugger window like this,

The thread 'Win32 Thread' (0xfbc) has exited with code 0 (0x0).
The program '[3264] xxxxx.exe: Native' has exited with code 0 (0x0).

If your application is multithread, you will see more "Win32 Thread" words in debugger window.

So my question is how to get every thread we have created exit status. In other word, how can we find the corresponding thread info based on debugger window.

let us see the example above. The thread 0xfbc, first, I think the value is the corresponding handle of the thread created. then I print this handle like this format "%08x". They are not the same value. I don't know geting the handle value is correct or not, if not, please remind me. If this conversion is true, how can we connect it with specific thread.

Another question, about exit code. I feel very puzzle. Though many people say if return value is zero, that definitely demonstrate that thread work fine. If not zero, thing seems complex. Some people say non-zero shows some trouble has happened. While other people say non-zero dosen't mean the thread is in trouble, it only show the status the thread return, also they say return value can be anything. At these words, It freak me out. If this is the case, how can I find out what has happened to the thread base on return code.

Hope anyone give me clues and any opinions will be much appreciated.

  • AnswerAnswer
    Azeem Khan - MSFT MSFT, Moderator - Posted on 2008年9月4日 0:51:48
    Hi Enrico,

    The values shown in brackets e.g. 0xfbc are the thread ids assigned by the OS. These values will match up with what is shown in the Threads window.

    As for the exit code value this is the value that the thread exited with. An exit code of 0 is used to mean there were no issues.  However the developer can choose to have thread exit with whatever code they want. So they may choose exit codes that indicate an error occurred etc. Also take a look at ExitThread at  http://msdn.microsoft.com/en-us/library/ms682659(VS.85).aspx and other methods related to this.

    Azeem Khan
    VS Debugger.
    Marked as answer by Azeem Khan - MSFT on 2008年9月4日 0:51:57
  • enrico00 - Posted on 2008年9月4日 22:56:27
     
    Azeem, thank you for your reply.

    I examine the value according to your prompt. Yeah, you are right.

    About exit code, I have make it clear.

    About thread id and exit code, I have another question. In my app, I create four threads,when I exit the app,I get info from debugger window like this:

    The thread 'Win32 Thread' (0xa14) has exited with code 1 (0x1).
    The thread 'Win32 Thread' (0xfbc) has exited with code 0 (0x0).
    The thread 'Win32 Thread' (0x960) has exited with code 0 (0x0).
    The thread 'Win32 Thread' (0x744) has exited with code 0 (0x0).
    The thread 'Win32 Thread' (0xe38) has exited with code 0 (0x0).
    The thread 'Win32 Thread' (0xe40) has exited with code 1 (0x1).
    The program '[504] xxxxx.exe: Native' has exited with code 2(0x2).


    According to thread id, I can identify exit with code 0 is created by my app. The remaing two threads are created by OS, so my question is how to deal with thread which is not created by app when the thread exit unsafely. Of course, the thread exit unsafely is due to the app's bug.
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值