广州建设网站哪家好,广州数商云,知乎 网站开发工具,长春疾控最新消息_beginthreadex 一定要自己写 CloseHandle 可以不用 _endthreadex 天哪,好久不 写忘记了.一直记得线程的句柄只是 createthread 才需要关闭,可能是我用 AfxBeginThread 太多了. 以后直接这样好了 ::CloseHandle((HANDLE)_beginthreadex(NULL, 0,threadRun_client,(void *)tp, 0…_beginthreadex 一定要自己写 CloseHandle 可以不用 _endthreadex 天哪,好久不 写忘记了.一直记得线程的句柄只是 createthread 才需要关闭,可能是我用 AfxBeginThread 太多了. 以后直接这样好了 ::CloseHandle((HANDLE)_beginthreadex(NULL, 0,threadRun_client,(void *)tp, 0, runThreadID )); -------------------------------------------------- http://wellwy.blog.51cto.com/blog/1609602/492009 _beginthreadex相关的东东 2011-02-12 16:57:52 标签_beginthreadex 谈 到Handle的问题_beginthread的对应函数_endthread自动的调用了CloseHandle而_beginthreadex的 对应函数_endthreadex则没有所以CloseHandle无论如何都是要调用的不过_endthread可以帮你执行自己不必写其他两种就 需要自己写(Jeffrey Richter强烈推荐尽量不用显式的终止函数用自然退出的方式自然退出当然就一定要自己写CloseHandle) // 在Windows下面比较常见的多线程创建函数是CreateThread(Windows自带的)和_beginthread、_beginthreadexC运行库的。 强烈推荐只用_beginthreadex参数上面与CreateThread基本一样比CreateThread好的就是它给每个线程维护一个tiddata数据块这对于多线程环境非常重要。《Windows核心编程》里也是这么说的。 用_beginthreadex还有个好处是线程结束后不会自己执行CloseHandle函数这样的话对于WaitFor系列函数的调用就比较方便了。_beginthread在线程结束的时候是会自己CloseHandle。 // _beginthread()存在几个缺陷如下 1 创建时不能将线程挂起。 2 _beginthread产生出来的线程会首先关闭自己的handle这样做是为了隐藏win32的实现细节因此_beginthread()传回的参数可能在当时是不可用的。因此没有这个handle你就无法等待他结束无法改变其参数无法获得结束代码。 /// You can call _endthread or _endthreadex explicitly to terminate a thread; however, _endthread or _endthreadex is called automatically when the thread returns from the routine passed as a parameter. Terminating a thread with a call to endthread or _endthreadex helps to ensure proper recovery of resources allocated for the thread.