Re: [問題] Thread Pool/Queue的設計方式

看板C_and_CPP作者 (Alien)時間16年前 (2009/03/24 03:09), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/4 (看更多)
※ 引述《littleboypis (littleboypis)》之銘言: : ※ [本文轉錄自 Programming 看板] : 作者: littleboypis (littleboypis) 看板: Programming : 標題: [問題] Thread Pool/Queue的設計方式 : 時間: Tue Mar 24 10:47:48 2009 : 各位好 : 最近想用C實作出一個Thread Pool or Thread Queue : 但是有一個問題 : 要怎麼Pool中的Thread可以不用一直while() { sleep } : 也可以保持在可隨時執行的狀態呢 : 如果說我要讓Thread不會被 return & pthread_exit : 就得要用while包住 [43] : 另外,想請問大家 : 有沒有比較推薦效能比較好的Thread Pool or Thread Queue(用C寫的)的Library : 謝謝 我以前用過或自己做的, 通常都是用 producer consumer queue. producer-consumer queue 詳細的做法去 google 一下就 找得到了. 大概而言是靠兩個 monitor/condition, 一個是代表 queue有 entries 一個代表 queue not full. 當 queue empty 的話, consumer (在你的情況, 是 pool 裡的 thread) 就 wait on queue有 entries 的 condition, 直到有人放東西進 queue 就 signal該 condition, 喚醒其中一個 thread 來讀東西工作. (queue not full 則是當 queue 的上限到達後, 讓 producer wait 直到有 consumer dequeu) 大概 Thread Pool 的效能分別不會大到哪裡. 選自己合用的比較重要吧. 試試看看 Glib 合不合用? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 202.155.236.82
文章代碼(AID): #19o4xOFJ (C_and_CPP)
討論串 (同標題文章)
文章代碼(AID): #19o4xOFJ (C_and_CPP)