Can Q_GLOBAL_STATIC replace KStaticDelete ?
thiago at kde.org
Mon Jan 8 17:41:55 GMT 2007
Olivier Goffart wrote:
>So can Q_GLOBAL_STATIC replace KStaticDeleter ?
>+ Q_GLOBAL_STATIC is thread safe while KStaticDeleter is not (but could
>eventually be modified)
KStaticDeleter cannot be made thread-safe unless we're willing to code a
pthreads implementation (not using Qt mutex and stuff, since those are
C++ non-POD objects). Rinse and repeat for each thread implementation
that KDE will support.
Also note that Q_GLOBAL_STATIC doesn't have a mutex, but an atomic
test-and-set. The result is that it is faster than a mutex or even g++'s
static initialiser guards. There isn't ever a contention case that
requires kernel arbitration.
The side effect is that in a real crunch condition, the target object may
be created twice (don't worry, one copy will be deleted; no leaks).
>- Q_GLOBAL_STATIC is not documented by Qt (at least i did not find the
>documentation), is it a part on the public API ?
It's not part of the public API, but it's safe enough for use in KDE code.
Same as Q_PRIVATE_SLOT that Simon suggested.
I also asked the TT maintainer to consider making QAtomic / QAtomicPointer
public as well. There's still time before Qt 4.3 is out for those things
to be documented.
>- KStaticDeleter support arrays, Q_GLOBAL_STATIC don't
You're probably better off using QVector, QList, QVarLengthArray or
Yes, Q_GLOBAL_STATIC doesn't support arrays. Do we really need this?
>Should KStaticDeleter be fixed to be thread safe ?
See above. The only solution to make KStaticDeleter work without resorting
to low-level stuff is to use Q_GLOBAL_STATIC in it :-)
>Or Should we remove KStaticDeleter in favor of Q_GLOBAL_STATIC ?
I'd say it's pretty obvious...
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
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
Size: 189 bytes
Desc: not available
More information about the kde-core-devel