作者oeoe7788 (oeoe)
看板C_and_CPP
标题[问题] 在linux c里有可以kill thread的function吗?
时间Fri Aug 21 16:57:01 2009
请问一下各位
在linux c里有可以kill thread的function吗?
如下~
有类似kill_thread(thread_id)????的function吗?
感谢!!!
-----------------------------------------
void Test()
{
while(1)
printf("123\n");
}
void main()
{
int conut = 0;
pthread_create(&thread_id, NULL, &Test, NULL);
if (conut < 10)
sleep(5);
//kill_thread(thread_id)????
}
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 220.133.37.155
1F:推 jlovet:可以用pthread_kill送一个讯号给thread, 08/21 17:04
2F:→ jlovet:thread自己决定收到什麽讯号要结束 08/21 17:04
3F:→ oeoe7788:不好意思~刚刚有试过还是不行~网路上有没有范例~不知道 08/21 17:57
4F:→ oeoe7788:方便留个sample code吗?感谢~ 08/21 17:58
5F:推 jlovet:嗯,用pthread_cancel好了, 08/22 01:15
6F:→ jlovet:不过,由别人来终止thread不是好事情,可能会memory leak 08/22 01:16