Misuse of K_GLOBAL_STATIC?
j.sixt at viscovery.net
Wed May 14 16:53:28 BST 2008
Thiago Macieira schrieb:
> KIMProxy *KIMProxy::instance()
> static KIMProxy *self;
> self = new KIMProxy;
> return self;
> Unlike the global statics, that ensures the "new" call happens exactly once
> (unless an exception is thrown). With the global statics, in the event of a
> reentrancy, the static could be built more than once, even though only one
> copy will survive.
In the light of this paper:
I'd be interested how Q_ONCE is implemented, in particular, whether it
uses the Double-Checked-Locking pattern.
[Summary: DCL tries to avoid locking the mutex if the object was already
allocated. The paper argues that DCL is unsafe because the compiler is
allowed to rearrange instructions in so many ways.]
More information about the kde-core-devel