#pragma once #include "Base.h" NS_BEGIN(Engine) class ENGINE_DLL CThreadHolder final : public CBase { private: CThreadHolder(); ~CThreadHolder(); public: template future> EnqueueJob(Function&& func, Args&&... args) { if (true == m_bStop_All) { throw runtime_error("ThreadPool 사용 중지됨"); } using return_type = invoke_result_t; auto job = make_shared>(bind(forward(func), forward(args)...)); future job_result_future = job->get_future(); { lock_guard lock(m_mtxJobQueue); m_JobQueue.push([job]() { (*job)(); }); } m_cvJobQueue.notify_one(); return job_result_future; } private: _uint m_iNumThreads = {}; vector m_Workers = {}; queue> m_JobQueue = {}; condition_variable m_cvJobQueue = {}; mutex m_mtxJobQueue = {}; _bool m_bStop_All = { true }; private: HRESULT Initialize(_uint iSize); void WorkerThread(); public: static CThreadHolder* Create(_uint iSize); virtual void Free() override; void Describe_Entity(); }; NS_END