|
发表于 2013-9-16 13:04:01
|
显示全部楼层
可以的,基于ACE_Task,不要基于ACE_Task_Base(没有队列缓存)
/// 线程池实现类
class CLASS_DECLSPEC ThreadPool : public ACE_Task<ACE_MT_SYNCH>
{
friend class WorkerThread;
public:
ThreadPool(size_t thread_num, size_t thread_idle_time = 1, const std::string& logger_file = "");
~ThreadPool(void);
virtual int svc(void);
int SubmitTask(const TaskBase* task);
int SubmitTask(int (*pFunc)(void *), void *pPara = NULL);
void JoinAll();
int CreateWorkThreads(size_t num = 0);
int DestroyWorkThreads(size_t num = 0);
private:
bool m_bDestroyed;
const size_t m_iSize;
ACE_Time_Value m_threadIdleTime; // idle thread wait time(second).
ACE_Thread_Mutex m_workersLock;
ACE_Condition_Thread_Mutex m_workersCondition;
//ACE_Thread_Semaphore m_destroyedSem;
ACE_Unbounded_Queue<WorkerThread *> m_workerThreads;
}; |
|