c++11 - std::atomic_bool not being initialized/read correctly -
i had problem starting , stopping background threads based on value of boolean flag. had asked here , got detailed answer here.
however, after using solution few days, seems me there wrong it. launch worker thread in someobject::dorun called in someobject::start should work in loop , quit when call someobject::stop:
struct someobject { someobject() { setdone(true); } std::atomic_bool done_; void dorun(); void setdone(bool v) { done_store(v); } bool isdone() { return done_.load(); } void start() { if (isdone()) { setdone(false); dorun(); } void stop() { setdone(true); } }; however, seems check isdone() in start() returns false , dorun() never gets called though have set done true in constructor.
the reason set done_ true in constructor , set false in start() want call start()/stop() repeatedly on same object.
what doing wrong here?
Comments
Post a Comment