0

I have a process which receives multiple jobs and picks a thread from thread pool and assigns a job to it, this thread in turn may spawn another set of threads from its own thread pool. Now when a STOP request for a job comes to the main process, it should be forwarded to corresponding thread for that request and all the threads associated with that job should clean themselves up and exit, My question is how to notify the worker threads about "STOP".

A global variable can be used and worker threads can poll it frequently but there are lot of functions that a worker can be doing, and adding checks everywhere could work.

Is there a clean approach? some kind of messaging layer. btw the code is C++

4

1 回答 1

1

Boost.Thread库是 pthread的包装器,也可移植到 Windows。该类boost::thread有一个interrupt()方法可以在下一个中断点中断线程

Boost.Thread 还有一个thread_group提供相关线程集合的类。thread_group还有一个在线程组中的每个线程上interrupt()调用的方法。interrupt()

于 2012-11-08T04:35:28.037 回答