[Interest] Heavily Commented Example: Simple Single Frontend with Two BackendsHi,

Thiago Macieira thiago.macieira at intel.com
Wed Oct 24 20:55:27 CEST 2012


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20121024/0cb1f47c/attachment.sig>


More information about the Interest mailing list