If you need such a framework in a single process application, boost::asio::io_service should be sufficient. Here is a working box sample class using boost::thread and boost::asio::io_service.
#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <boost/thread.hpp>
class IWorkerThreadJob
{
public:
virtual ~IWorkerThreadJob(){};
virtual void execute() = 0;
};
class BoostBasedWorkingBox
{
public:
BoostBasedWorkingBox():
m_IOServiceWork(m_IOService), // Give some work to io_service or else it will simply return from ::run method .
m_WorkerThread(boost::bind(&boost::asio::io_service::run, &m_IOService))
{}
~BoostBasedWorkingBox()
{
m_IOService.stop();
m_WorkerThread.join();
}
void processJob(IWorkerThreadJob* pJob)
{
m_IOService.post(boost::bind(&IWorkerThreadJob::execute,pJob));
}
protected:
boost::thread m_WorkerThread;
boost::asio::io_service m_IOService;
boost::asio::io_service::work m_IOServiceWork;
}
Use:-
Implement IWorkerThreadJob interface.
Call processJob method from multiple clients.
Here boost::asio::io_service acts as a thread safe queue.