Re: C++ Function Static Initialization, Thread-Safe?
- From: "Chris Thomasson" <xxx@xxxxxxx>
- Date: Tue, 29 Jul 2008 21:46:22 -0700
"Chris Thomasson" <xxx@xxxxxxx> wrote in message news:g6oo3s$a0p$1@xxxxxxxxxxx
"Chris Thomasson" <xxx@xxxxxxx> wrote in message news:g6omf2$2lc$1@xxxxxxxxxxx"David Schwartz" <davids@xxxxxxxxxxxxx> wrote in message news:eb0bf392-2712-452f-8d9f-c5b9783c1e25@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Jul 29, 4:01 pm, Brian Cole <col...@xxxxxxxxx> wrote:
> Is my test good enough to catch this race condition?
Not unless you test on every possible combination of hardware,
compiler versions, and threading libraries (both in development and
deployment).
Do these systems
actually support thread-safe function static initialization?
It's illegal under POSIX. But it's also inherently impossible to
support because the semantics are not defined.
[...]
If the platform internally uses a lock, it must deal with all the
consequences of using such a lock. These includes priority inversion,
lock order issues (suppose the constructor for the static itself
constructs statics), and deadlock.
Not if the lock is recursive.
One more thing, the lock needs to be singular. In other words, there needs to be a single lock for all singletons to use. If this is not the case, then locking order violations will occur.
Here is example implementation:
http://groups.google.com/group/comp.programming.threads/msg/c5c68a037d98452e
What do you think David? AFAICT, its immune from deadlocking even in the presence of nested singletons in multiple ctors called from multiple threads.
[...]
.
- Follow-Ups:
- Re: C++ Function Static Initialization, Thread-Safe?
- From: David Schwartz
- Re: C++ Function Static Initialization, Thread-Safe?
- References:
- C++ Function Static Initialization, Thread-Safe?
- From: Brian Cole
- Re: C++ Function Static Initialization, Thread-Safe?
- From: David Schwartz
- Re: C++ Function Static Initialization, Thread-Safe?
- From: Chris Thomasson
- Re: C++ Function Static Initialization, Thread-Safe?
- From: Chris Thomasson
- C++ Function Static Initialization, Thread-Safe?
- Prev by Date: Re: atomically thread-safe Meyers singleton impl...
- Next by Date: Re: lock free queue implementation - thoughts?
- Previous by thread: Re: C++ Function Static Initialization, Thread-Safe?
- Next by thread: Re: C++ Function Static Initialization, Thread-Safe?
- Index(es):
Relevant Pages
|