Calling abstract function on boost thread, does not interrupt at interruption_point
I have created an abstract base class to allow for multiple implementation of a task, which can be called generically via MFC dialog. This task needs to be able to be interrupted if the user clicks cancel.
abstract_dll.h:
class abstract_dll
{
public:
virtual void my_task(CFeedback *fb)=0;
}
Where CFeedback
is an abstract class to control user feedback (ie. progress bar)
concrete_dll.h:
class concrete_dll
{
virtual void my_task(CFeedback *fb)
{
//do some work
//step progress bar
boost::this_thread::interruption_point();
//do some work
//step progress bar
boost::this_thread::interruption_point();
}
}
extern "C" abstract_dll* get_class() { return new concrete_dll(); }
Now within the MFC Dialog I load the appropriate concrete_dll and initialize my abstract_dll *dll = module->get_class();
Then start a new boost::thread
which calls the dll->my_task(fb);
Then when I call thread.interrupt()
. The thread is never interrupted, and it never excepts at my interruption_points. I have traced the thread ID it is the same until we're in the concrete_dll implementation, then I just get 0x0000 for the thread id.
Any thoughts? PS. The code above is just pseudo code for wha开发者_如何学Ct I have. My actual code compiles and runs, I just can't get it to interrupt.
I think the answer to your question is here:
http://lists.boost.org/boost-users/2010/01/55171.php
In short: you need to link to DLL version of boost:threads both in your project and DLL. Just put the:
#define BOOST_THREAD_USE_DLL
before <boost/thread.hpp>
inclusion (or in the project propeties)
BR
精彩评论