这2个函数都是强制退出线程和进程
最大的特点是 不会返回 进去就出不来了
如果终结主线程 比如在主线程中C/C++申请对象 得不到正确的释放
应该调用_endthreadex
在线程内申请的局部变量 不会析构 核心编程EXITPROCESS
Code#include <iostream.h> #include <process.h> #include <stdlib.h> #include <windows.h> class A { public: A() { cout<<"A"<<endl; } ~A() { cout<<"A"<<endl; } void fun() { cout<<"cccc"<<endl; } }; unsigned __stdcall ThreadFunc(void* param); int main(int argc, char* argv[]) { unsigned threadid = 0; HANDLE hh= (HANDLE) _beginthreadex(NULL,NULL,ThreadFunc,NULL,NULL,&threadid); WaitForSingleObject(hh,INFINITE); return 0; } unsigned __stdcall ThreadFunc(void* param) { A A1; cout << "Sub thread is runned" << endl; ExitThread(0); return 0; }