weixin_40166710
weixin_40166710
2017-11-21 05:03

主程序中用TerminateThread结束一个会运行长时间线程,然后主程序下面代码运行不了

10
  • c++
  • c
  • 多线程

图看不清,测试代码如下
struct A
{
int a;
int b;
};
void threadfun(void *lpVoid);
void CombatPlan(int a, int b)
{
if(a)
{
cout<<a;
CombatPlan(a-1,b);
}
}

void threadFunc(void lpVoid)
{

A *p = (A
)lpVoid;
CombatPlan(p->a, p->b);
_endthread;
}

int main()
{
A a;
a.a = 4444;
a.b = 333;
HANDLE handle =(HANDLE)_beginthread((void(_cdecl*)(void*))threadFun,0,(void*)&a);
sleep(900);
TerminateThread(handle,0);
cout<<"hahaha";//运行不了
}

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

3条回答