0

The following program produces a segmentation fault, although I don't see any undefined behaviour in the code. It has been compiled with GCC 4.7.3. Do you know the reason of the fault or a possible work-around? Also, it seems boost::future does not exist in v1.53 yet, so I should probably rely on boost::unique_future. I cannot upgrade to any version above > 1.53 and I really need the "make_ready_at_thread_exit()" feature.

#define BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK
#include <boost/thread.hpp>
#include <boost/thread/future.hpp>

namespace th = boost;

struct S {
    th::packaged_task<void()> task;
    th::unique_future<void> future;
    void start();
    void stop();
};

void S::start() {
    task = th::packaged_task<void()>{ [this] () {}};
    future = task.get_future();                
    task.make_ready_at_thread_exit();
}

void S::stop() {
    future.wait();                
}

int main() {
    S s;
    s.start();
    s.stop();
}
Martin
  • 9,089
  • 11
  • 52
  • 87
  • 2
    I can only say this seems bugged in 1_53/1_54 (althought the entire future is unrelated and not required to reproduce the error). It does work on 1_55 just fine. You can probably find the bug report that fixed this. But I'm not really happy to go looking for it. – sehe Mar 13 '14 at 23:00
  • 1
    Just for info http://coliru.stacked-crooked.com/a/50f126e6040ef197 – sehe Mar 13 '14 at 23:09

0 Answers0