[Interest] QMap and thread-safe.

william.crocker at analog.com william.crocker at analog.com
Wed Jul 24 04:20:48 CEST 2013


> If you want to be 100% certain, I suggest you do your own simple map
> implementation. It's easy enough to do, if you don't have a huge set of
> requirements. And you can probably use the QMap hashing, I'm pretty sure
> that is thread safe.
>
> Whether you want to go to this or take the chance probably depends on
> how critical this code is.
>

Thanks. More thoughts...

Classes like QString and QMap were designed (using implicit sharing) to
provide for thread-safe, high-speed pass by value. So, in the following,
is it true that AAA is not guaranteed to work, but BBB is?

bool
MyContains( const QMap<QString,QString> &map, const QString &str ) {
     return map.contains(str);
}

QMap<QString,QString> GlobalMap;

bool
Func( const QString &str ) {

       // AAA: This might not work from an MT context???
     return GlobalMap.contains(str);

       // BBB: But, this always will???
     return MyContains(GlobalMap,str);
}





More information about the Interest mailing list