Fix ThreadPool exception on shutdown.

Fixes #3891
This commit is contained in:
Gunnar Beutner 2013-05-13 09:58:24 +02:00
parent 36a45059f9
commit f4d04f8172
2 changed files with 6 additions and 3 deletions

View File

@ -197,13 +197,14 @@ void ThreadPool::QueueThreadProc(int tid)
* Appends a work item to the work queue. Work items will be processed in FIFO order.
*
* @param callback The callback function for the work item.
* @returns true if the item was queued, false otherwise.
*/
void ThreadPool::Post(const ThreadPool::WorkFunction& callback)
bool ThreadPool::Post(const ThreadPool::WorkFunction& callback)
{
boost::mutex::scoped_lock lock(m_Mutex);
if (m_Stopped)
BOOST_THROW_EXCEPTION(std::runtime_error("ThreadPool has been stopped."));
return false;
WorkItem wi;
wi.Callback = callback;
@ -211,6 +212,8 @@ void ThreadPool::Post(const ThreadPool::WorkFunction& callback)
m_WorkItems.push_back(wi);
m_WorkCV.notify_one();
return true;
}
void ThreadPool::ManagerThreadProc(void)

View File

@ -46,7 +46,7 @@ public:
void Stop(void);
void Join(void);
void Post(const WorkFunction& callback);
bool Post(const WorkFunction& callback);
private:
enum ThreadState