[問題] 在linux c裡有可以kill thread的function嗎?

看板C_and_CPP (C/C++)作者 (oeoe)時間16年前 (2009/08/21 16:57), 編輯推噓2(204)
留言6則, 2人參與, 最新討論串1/1
請問一下各位 在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

08/21 17:04, , 1F
可以用pthread_kill送一個訊號給thread,
08/21 17:04, 1F

08/21 17:04, , 2F
thread自己決定收到什麼訊號要結束
08/21 17:04, 2F

08/21 17:57, , 3F
不好意思~剛剛有試過還是不行~網路上有沒有範例~不知道
08/21 17:57, 3F

08/21 17:58, , 4F
方便留個sample code嗎?感謝~
08/21 17:58, 4F

08/22 01:15, , 5F
嗯,用pthread_cancel好了,
08/22 01:15, 5F

08/22 01:16, , 6F
不過,由別人來終止thread不是好事情,可能會memory leak
08/22 01:16, 6F
文章代碼(AID): #1AZc5Usx (C_and_CPP)
文章代碼(AID): #1AZc5Usx (C_and_CPP)