作者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