Can Q_GLOBAL_STATIC replace KStaticDelete ?

Thiago Macieira thiago at
Wed Jan 17 23:48:44 GMT 2007

Matthias Kretz wrote:
>- removed K_GLOBAL_STATIC_WITH_ARGS in favor of putting all ctor and
> dtor calls in the KGlobalStatic class so that singletons can declare
> there ctor and dtor private/protected and make
> KGlobalStatic<SingletonClass> a friend. 
> - replaced 
> q_atomic_test_and_set_ptr with QBasicAtomicPointer::testAndSet 

Problem with your patch:
You're using an atomic test-and-set to make the object assignment 
thread-safe, but your KGlobal::addGlobalStatic isn't thread-safe.

Either you make it fully thread-safe by adding a mutex protection around 
_globalStatics or you can drop thread safety and drop the QAtomic usage.

If you add a mutex, you can drop QAtomic too, since you can protect the 
pointer assignment with the mutex. In the documentation, be sure to note 
that K_GLOBAL_STATIC will be slower than Q_GLOBAL_STATIC.

Note: as an irony, the mutex must be Q_GLOBAL_STATIC :-)

> - moved 
> public static variables of KGlobal into the .cpp file (making it
> file-static) where possible

Can you make another patch for that?

  Thiago Macieira  -  thiago (AT) - thiago (AT)
    PGP/GPG: 0x6EF45358; fingerprint:
    E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <>

More information about the kde-core-devel mailing list