開發平台(Platform): (Ex: Win10, Linux, ...)
OSX / Xcode
編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出)
clang
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
Hi大家好
先附上github
https://github.com/clydewu/Cldlib/tree/master/Cldlib
因為之前是以C++11標準,還沒有Semaphore
所以用condition variable實作了Semaphore
然後使用這個semaphore來給予queue最大最小值的限制
若queue.size()超過max或小於min,那嘗試push或pop的的thread就會等待
實作的方式是一個樣板類別,裡面有deque跟semaphore
template <typename T> class SemaphoreQueue
{
deque<T> queue_;
Semaphore* in_semaphore_;
Semaphore* out_semaphore_;
}
那現在希望同樣的邏輯可以reuse在List或其他容器上
有點不知道怎麼做
初步的想法是要有兩個樣板參數
一個是容器本身的類型
一個是容器裝的東西的類型
e.g.
template <typename T1, typename T2> class SemaphoreContainer
{
T1<T2> queue_;
Semaphore* in_semaphore_;
Semaphore* out_semaphore_;
}
但這樣根本編不過XD
不知道這是要用什麼c++的機制來做呢?
基礎不紮實,關鍵字請求摟!