The Solver::interrupt(){ asynch_interrupt = true; } with bool asynch_interrupt; should not really work -- it's not clear that asynch_interrupt can be changed from another thread and the compiler is completely at liberty to optimize out the check (as I suspect it does). It should have lock/atomic/etc. primitives around it so the compiler is aware that it can be changed from elsewhere. Also note that using volatile does not fix this issue -- it does not signal the system that another thread might change the value and so it does not force a memory sync between the threads. A memory barrier is needed before every access to it from any thread, i.e. one after the change in interrupt() and one everywhere where the value of asynch_interrupt is checked.
The
Solver::interrupt(){ asynch_interrupt = true; }
withbool asynch_interrupt;
should not really work -- it's not clear thatasynch_interrupt
can be changed from another thread and the compiler is completely at liberty to optimize out the check (as I suspect it does). It should have lock/atomic/etc. primitives around it so the compiler is aware that it can be changed from elsewhere. Also note that usingvolatile
does not fix this issue -- it does not signal the system that another thread might change the value and so it does not force a memory sync between the threads. A memory barrier is needed before every access to it from any thread, i.e. one after the change ininterrupt()
and one everywhere where the value ofasynch_interrupt
is checked.