We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
class ThreadPool
{
typedef std::shared_ptr<std::thread> threadPtr; typedef std::function<void(void)> threadFuncCallback;
public:
ThreadPool(int threadNum = 10) : m_iThreadNum(std::thread::hardware_concurrency()) , m_threadFuncQueue(10) { startAllThread(m_iThreadNum); } ~ThreadPool() { } void AddTask(threadFuncCallback& task) { m_threadFuncQueue.Put(task); } void Stop() { m_brunning = false; for (auto thd: m_threadQueue) { thd->join(); } }
private:
void startAllThread(int numThreads) { m_brunning = true; for (int i=0; i<numThreads; i++) { m_threadQueue.push_back(std::make_shared<std::thread>(&ThreadPool::RunInThread, this)); } } void RunInThread(void) { while (m_brunning) { auto task = m_threadFuncQueue.Take(); task(); } }
int m_iThreadNum; std::deque<threadPtr> m_threadQueue; std::atomic_bool m_brunning; BoundedBlockingQueue<threadFuncCallback> m_threadFuncQueue;
};
The text was updated successfully, but these errors were encountered:
No branches or pull requests
ifndef THREAD_POOL_H__
define THREAD_POOL_H__
include "BoundedBlockingQueue.h"
include
include
include
include
class ThreadPool
{
public:
private:
private:
};
endif
The text was updated successfully, but these errors were encountered: