On quarta-feira, 24 de outubro de 2012 14.37.14, K. Frank wrote: > So, to summarize what you're saying, real world hardware is not > excessively perverse. > > Therefore the volatile-bool scheme for signalling a thread to stop will > work in practice (but volatile is not good enough for full-featured thread > synchronization), because the hardware will cause the updated value > of the stop flag to become visible to the polling thread in a reasonable > amount of time. The polling thread might run a little longer than expected, > but it will stop in a reasonable amount of time (for some reasonable > definition of "reasonable").
Right.
But the correct way of doing that is to use a C11 or C++11 atomic load in
relaxed mode:
atomic_int flag = ATOMIC_VAR_INIT(0);
/* signal */
atomic_store(&flag, 1);
/* check if set */
if (atomic_load(&flag))
break;
C++11 has a C++ API in addition. QAtomicInt is similar to C++11's
std::atomic<int>.
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center
signature.asc
Description: This is a digitally signed message part.
_______________________________________________ Interest mailing list [email protected] http://lists.qt-project.org/mailman/listinfo/interest
