int main(int argc, char** argv)
{
        NotificationQueue queue;

        // create some worker threads
        Worker worker1("Worker 1", queue);
        Worker worker2("Worker 2", queue);
        Worker worker3("Worker 3", queue);
        MyProducer producer1("Producer1", queue);
        Thread tWorker1, tWorker2, tWorker3, tProducer1;
        tWorker1.start(worker1);
        tWorker2.start(worker2);
        tWorker3.start(worker3);
        
        //Thread::sleep(3000);
        tProducer1.start(producer1);
        tProducer1.join();
        Thread::sleep(20000);

        // stop all worker threads
        queue.wakeUpAll();
        

        return 0;
}
Пример #2
0
int main(int argc, char** argv)
{
	NotificationQueue queue;
	
	// create some worker threads
	Worker worker1("Worker 1", queue);
	Worker worker2("Worker 2", queue);
	Worker worker3("Worker 3", queue);

	// start worker threads
	ThreadPool::defaultPool().start(worker1);
	ThreadPool::defaultPool().start(worker2);
	ThreadPool::defaultPool().start(worker3);

	// distribute some work
	for (int i = 0; i < 50; ++i)
	{
		queue.enqueueNotification(new WorkNotification(i));
	}
	
	// wait until queue is empty and all threads are 
	// waiting for new work.
	while (!queue.empty()) Thread::sleep(200);
	Thread::sleep(500);
	
	// stop all worker threads
	queue.wakeUpAll();
	ThreadPool::defaultPool().joinAll();
	
	return 0;
}