//////////////////////////////////////////////////////////////////////////// // CThreadPool クラスのインタフェース宣言 // //////////////////////////////////////////////////////////////////////////// #if !defined( THREADPOOL_H_INCLUDED_ ) #define THREADPOOL_H_INCLUDED_ #include "Thread.h" #include "Semaphore.h" #include using namespace std; class CDmyThread; class CPooledThread; class CThreadPool { public: CThreadPool(); ~CThreadPool(); bool run( CDmyThread *pThread ); // スレッドのたまり場 void WaitNextJob( CThread *pTh ); protected: // プールにスレッドを追加する bool AddThread(); CSemaphore semaGate; // スレッドの流量を制限する int ThCounter; // 現在使用中のスレッドの数 vector< CPooledThread* > vThread; // スレッドの配列 // スレッド割り当て要求を待っている、外部のスレッドオブジェクト CDmyThread *pExThread; CSemaphore semaExThread; // 終了を待ち合わせるため bool ExitFlg; CSemaphore semaExit; }; class CPooledThread : public CThread { public: CPooledThread( CThreadPool *argPool ) : pPool( argPool ) {}; ~CPooledThread(){}; void run() { pPool->WaitNextJob( this ); }; private: CThreadPool *pPool; }; #endif // THREADPOOL_H_INCLUDED_