Use a FIFO queue for the tasks in the thread pool.

This commit is contained in:
Gunnar Beutner 2012-06-18 06:29:48 +02:00
parent bd1e8b2395
commit 1d8331ecd8
4 changed files with 8 additions and 6 deletions

View File

@ -91,7 +91,7 @@
#include <map>
#include <list>
#include <algorithm>
#include <stack>
#include <deque>
using std::string;
using std::vector;
@ -100,7 +100,7 @@ using std::list;
using std::set;
using std::multimap;
using std::pair;
using std::stack;
using std::deque;
using std::stringstream;

View File

@ -25,7 +25,7 @@ ThreadPool::~ThreadPool(void)
void ThreadPool::EnqueueTask(Task task)
{
unique_lock<mutex> lock(m_Lock);
m_Tasks.push(task);
m_Tasks.push_back(task);
m_CV.notify_one();
}
@ -44,8 +44,8 @@ void ThreadPool::WorkerThreadProc(void)
return;
}
task = m_Tasks.top();
m_Tasks.pop();
task = m_Tasks.front();
m_Tasks.pop_front();
}
task();

View File

@ -23,7 +23,7 @@ private:
mutex m_Lock;
condition_variable m_CV;
stack<Task> m_Tasks;
deque<Task> m_Tasks;
thread_group m_Threads;
bool m_Alive;

View File

@ -29,8 +29,10 @@
#include <i2-base.h>
#include <stack>
#include <fstream>
using std::stack;
using std::istream;
using std::ostream;
using std::cin;