#include "CommonThread.h" CommonThread::CommonThread(SimpleQueuePtr queue) { this->queue = queue; } void CommonThread::operator()() { ElementPtr elem; cout << "Thread" << this << " is running." << endl; while(elem = queue->pop()) { for(int i=0; i< 5000; i++) { /*no op*/} boost::mutex::scoped_lock scoped_lock(queue->mutex); if (elem) { cout << this <<": got element #" << elem->getString() << endl; } } cout << "Thread" << this << " is terminating..." << endl; } int main( void ) { SimpleQueuePtr queue = SimpleQueuePtr(new SimpleQueue()); boost::thread_group threads; for(int i = 0; i < 10; i++) { threads.create_thread(CommonThread(queue)); } threads.join_all(); return 0; }