KStringHandler: stateless/reentrant/thread-safe?

Thiago Macieira thiago at kde.org
Sun Oct 28 16:22:39 GMT 2012


On domingo, 28 de outubro de 2012 17.12.31, Frank Reininghaus wrote:
> The functions with statics are:
> 
> 1. KStringHandler::isUtf8(const char *)
> 
> http://api.kde.org/4.9-api/kdelibs-apidocs/kdecore/html/kstringhandler_8cpp_
> source.html#l00204

Do notice that it's static const POD. Since it's not modifying anything, it's 
thread-safe. And stateless.

> 2. KStringHandler::from8Bit(const char *)
> 
> http://api.kde.org/4.9-api/kdelibs-apidocs/kdecore/html/kstringhandler_8cpp_
> source.html#l00289
> 
> The first one contains a static array of chars, which looks safe to
> me. The second has a static reference to a QString which is generated
> using KGlobal::staticQString(const char*). I'm not entirely sure if
> that is safe as well.

That's a static const non-POD created by a non-constexpr. That means it's 
initialised on the first run.

It's thread-safe on GCC and C++11, but not on other conditions.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- 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://mail.kde.org/pipermail/kde-core-devel/attachments/20121028/590b1650/attachment.sig>


More information about the kde-core-devel mailing list