首页 > 其他分享 >How can I determine if a Win32 thread has terminated?

How can I determine if a Win32 thread has terminated?

时间:2023-02-02 23:14:36浏览次数:71  
标签:sheet thread share Win32 How popover data se

How can I determine if a Win32 thread has terminated?

Ask Question Asked 14 years, 2 months ago  

How can I determine if a Win32 thread has terminated?

The documentation for GetExitCodeThread warns to not to use it for this reason since the error code STILL_ACTIVE can be returned for other reasons.

Thanks for the help! :)

Share Edit   asked Nov 19, 2008 at 5:17 Uhall's user avatar Uhall 5,54377 gold badges2424 silver badges1919 bronze badges
  •   If the thread is your own you can make sure that all your threads return 0. So this problem will never arise. I think ExitCodeThread() is the better solution than the accepted answer in case you are needing this for your own threads because the "other reasons" mentioned in the MSDN are simply that YOU return the exit code STILL_ACTIVE from your thread routine. So simply don't do it.  – Elmue  Aug 30, 2018 at 14:15 
Add a comment

2 Answers

Reset to default 7

The documentation you link to warns against using STILL_ACTIVE as a return code, since it can't be distinguished from the return value used to indicate an active thread. So don't use it as a return value and you won't have this problem.

Share Edit   answered Nov 19, 2008 at 5:22 Shog9's user avatar Shog9 155k3434 gold badges230230 silver badges233233 bronze badges Add a comment   40  

MSDN mentions that "When a thread terminates, the thread object attains a signaled state, satisfying any threads that were waiting on the object".

So, you can check for whether a thread has terminated by checking the state of the thread handle - whether it's signaled or not:

DWORD result = WaitForSingleObject( hThread, 0);

if (result == WAIT_OBJECT_0) {
    // the thread handle is signaled - the thread has terminated
}
else {
    // the thread handle is not signaled - the thread is still alive
}
Share Edit   answered Nov 19, 2008 at 5:45

标签:sheet,thread,share,Win32,How,popover,data,se
From: https://www.cnblogs.com/ioriwellings/p/17087683.html

相关文章

  • 7. CTFshow 反序列化 web258
    一、代码<?phperror_reporting(0);highlight_file(__FILE__);classctfShowUser{private$username='xxxxxx';private$password='xxxxxx';private$......
  • 6. CTFshow 反序列化 web257
    一、代码<?phperror_reporting(0);highlight_file(__FILE__);classctfShowUser{private$username='xxxxxx';private$password='xxxxxx';private$......
  • 一文讲尽Thread类的源码精髓
    摘要:今天,我们就一起来简单看看Thread类的源码。本文分享自华为云社区《【高并发】Thread类的源码精髓》,作者:冰河。前言最近和一个朋友聊天,他跟我说起了他去XXX公司面试......
  • 一文讲尽Thread类的源码精髓
    摘要:今天,我们就一起来简单看看Thread类的源码。本文分享自华为云社区《​​【高并发】Thread类的源码精髓​​》,作者:冰河。前言最近和一个朋友聊天,他跟我说起了他去XXX公司......
  • ThreadLocal
    ThreadLocal在学习ThreadLocal之前,我们需要先确认一个事情,就是客户端发送的每次http请求,对应的在服务端都会分配一个新的线程来处理,瑞吉外卖在处理过程中涉及到下面类中......
  • What does kb show for 64 bit processes?
    Whatdoeskbshowfor64bitprocesses?Ihaverecentlymadeamistakeanalyzingacallstack,becauseIdidn'texpecttheapplicationtobe64bit.Iha......
  • ‍‌‌⁤‍⁤⁢‌‍⁡​​⁢⁤‌​​⁣⁤⁡​⁢‍​⁣​‍‍​​⁤⁡​‍⁡​‍⁡‬⁢
    TalentOrghttps://talent.talentorg.cn/opening-jobs‍‌‌⁤‍⁤⁢‌‍⁡​​⁢⁤‌​​⁣⁤⁡​⁢‍​⁣​‍‍​​⁤⁡​‍⁡​‍⁡‬⁢⁢​​⁡⁢TalentOrg--远程工......
  • error: undefined reference to `vtable for QDemoThread‘
    问题描述:error:undefinedreferenceto`vtableforXXXXXXXXXX‘出现原因:使用Qt对于自行创建的类如果需要支持信号和槽机制,必须要在类内头部位置添加Q_OBJECT宏。如果使......
  • ThreadPoolExecutor线程池参数设置技巧
    一、ThreadPoolExecutor的重要参数1、corePoolSize:核心线程数*核心线程会一直存活,及时没有任务需要执行*当线程数小于核心线程数时,即使有线程空闲,线程池也会优先创建......
  • 3. CTFshow 反序列化 web254
    一、源码<?phperror_reporting(0);highlight_file(__FILE__);include('flag.php');classctfShowUser{public$username='xxxxxx';public$password='xxx......