Re: C++ Function Static Initialization, Thread-Safe?



"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.


[...]

.



Relevant Pages

  • Re: C++ Function Static Initialization, Thread-Safe?
    ... actually support thread-safe function static initialization? ... consequences of using such a lock. ... constructs statics), and deadlock. ... there needs to be a single lock for all singletons to use. ...
    (comp.programming.threads)
  • Re: static variable lifetime in WebService
    ... Yup, my statics are protected with a lock, so I don't think there is any ... threading issues here. ... The main concern is why the memory is NOT being released for the dll. ...
    (microsoft.public.dotnet.languages.csharp)
  • [ANNOUNCE] 2.6.31-rc4-rt1
    ... This is a major rework of the rt patch series. ... interrupt threading is now a pure extension of the mainline ... type in the lock definition. ...
    (Linux-Kernel)
  • Re: [ANNOUNCE] 2.6.31-rc4-rt1
    ... This is a major rework of the rt patch series. ... interrupt threading is now a pure extension of the mainline ... type in the lock definition. ...
    (Linux-Kernel)
  • Re: Monitor (lock)
    ... I actually read through your tutorial on C# threading on your ... > The object the reference refers to is basically irrelevant. ... > Monitor instances created purely for the sake of locking. ... > lock in terms of keeping the lock private. ...
    (microsoft.public.dotnet.framework)