作者gamed (Maiko)
看板C_and_CPP
標題[問題] pthread 停止問題
時間Wed Apr 22 03:46:02 2015
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
GCC
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
pthread
問題(Question):
是這樣的
我目前程式 main 會處理大部份的事情
但因某種需求要特別處理
所以我多開一條 thread 來做
我使用 linux pthread
pthread_create function 來建一條 thread
因為這 thread 裡有 while(1)
我希望當這thread 有某個情況能停止掉這thread
所以我該如何停止住thread 才是對的呢?
google 一下是該在這個thread 裡面使用 pthread_exit(0)??
那如果要再重啟同樣的thread 是要呼叫一次pthread_create??
抱歉 我是程式新手
剛測試一下是OK的
但想了解正確的做法
謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 219.70.202.53
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1429645565.A.4B7.html
→ pili100: 可以貼source code嗎 04/23 20:56
→ noonOut: 你要停止還是暫停? 04/24 14:07
推 jynyptt: pthread_cancel 之類的吧 04/29 14:12