Boost logo

Boost :

From: Steven Watanabe (steven_at_[hidden])
Date: 2007-02-05 16:43:48


AMDG

Fabien Niñoles <fabien.ninoles <at> gmail.com> writes:

>
> You're perfectly right on this issue: only the second_lock is necessary, and
> pInstance must also be volatile (I never write such code myself, I always
> used Loki implementation when I need a singleton). As for instanciation,
> the standard ensure that a local static variable will only be initialized
> once, before entrance to the block scope. How this is handled in
> multi-thread program? I guess it's depend on your threaded platform. As
> for where the mutexes is defined... Well, that's also depends on the class
> policy (and what's the mutex implementation permits).

The zero-initialization (8.5) of all local objects with
static storage duration (3.7.1) is performed before any
other initialization takes place. (6.7/4)

A mutex is overkill. In this case a
volatile class static with a trivial constructor
and a volatile boolean flag is enough.

In Christ,
Steven Watanabe


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk