[Development] How qAsConst and qExchange lead to qNN

Ulf Hermann ulf.hermann at qt.io
Wed Nov 16 09:09:37 CET 2022


> The above isn't thread-safe, it isn't even re-entrant, in the same way
> that iteration using iterators isn't. This is a known issue whenever you
> hand out references, and it's nothing that violates our
> const-is-thread-safe promise, otherwise

... which is why we prefer to hand out (implicitly shared) copies rather 
than references.

> 
>       static const QMap map = ~~~;
>       // T1
>       map["x"].size();

Our container classes do hand out references, because containers have 
to. But in other places we avoid it.

best regards,
Ulf


More information about the Development mailing list