在boost线程上调用抽象函数,不会在interruption_point处中断

时间:2011-09-02 18:08:22

标签: multithreading boost mfc abstract-class

我创建了一个抽象基类,允许多个任务的实现,这可以通过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对话框中我加载了相应的concrete_dll并初始化了我的abstract_dll *dll = module->get_class();

然后开始调用boost::thread

的新dll->my_task(fb);

然后我打电话给thread.interrupt()。线程永远不会中断,它永远不会超出我的interruption_points。我已经跟踪了线程ID它是相同的,直到我们在concrete_dll实现中,然后我只得到0x0000的线程ID。

有什么想法? PS。上面的代码只是我所拥有的伪代码。我的实际代码编译并运行,我无法让它中断。

1 个答案:

答案 0 :(得分:2)

我认为你的问题的答案就在这里:

http://lists.boost.org/boost-users/2010/01/55171.php

简而言之:您需要在项目和DLL中链接到boost版本的boost:threads。只需输入:

#define BOOST_THREAD_USE_DLL

<boost/thread.hpp>包含之前(或在项目属性中)

BR

相关问题