在boost线程上调用抽象函数,不会在interruption_point处中断
我创建了一个抽象基类以允许任务的多次实现,可以通过 MFC 对话框进行一般调用。如果用户单击“取消”,则该任务需要能够中断。
abstract_dll.h:
class abstract_dll
{
public:
virtual void my_task(CFeedback *fb)=0;
}
其中CFeedback
是一个抽象类,用于控制用户反馈(即进度条)
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(); }
现在位于MFC对话框中我加载适当的crete_dll并初始化我的abstract_dll *dll = module->get_class();
然后启动一个新的boost::thread
来调用dll->my_task(fb);
然后当我调用 thread.interrupt()
时。该线程永远不会被中断,并且永远不会在我的interruption_points 处例外。我已经跟踪了线程 ID,直到我们进入crete_dll 实现为止,它都是相同的,然后我只得到 0x0000 作为线程 id。
有什么想法吗?附言。上面的代码只是我所拥有的伪代码。我的实际代码编译并运行,我只是无法让它中断。
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 what I have. My actual code compiles and runs, I just can't get it to interrupt.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您问题的答案就在这里:
http://lists.boost .org/boost-users/2010/01/55171.php
简而言之:您需要在项目和 DLL 中链接到 DLL 版本的 boost:threads 。只需将:放在
包含之前(或在项目属性中)BR
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:
before
<boost/thread.hpp>
inclusion (or in the project propeties)BR