Boost logo

Boost :

From: Martin Bonner (martin.bonner_at_[hidden])
Date: 2006-10-30 03:49:16

----Original Message----
From: boost-bounces_at_[hidden]
[mailto:boost-bounces_at_[hidden]] On Behalf Of Roland Schwarz
Sent: 29 October 2006 15:45 To: Boost
Subject: [boost] [thread] A simply static initializeable mutex

> Triggered by the question how to do
> static initialization of a mutex, I
> tried to write one that is.
> The most basic initialization that
> wil be performed by the compiler, is
> zero initialization of static (POD)
> objects. This kind of initialization
> will take place before any other
> initializations.
> Consequently the mutex is initialized
> by its mere declaration. However this
> does come at a price:
[snip careful list of caveats]

You may be able to do a little better. The standard says "The storage
for objects with static storage duration (3.7.1) shall be
zeroinitialized (8.5) before any other initialization takes place."
What is more, most normal operating systems give programs pages of
memory that are zero-initialized, so compilers would have to do work to
avoid this.

I think that means you can declare constructors and STILL have the
object well behaved.

Martin Bonner
Pi Technology, Milton Hall, Ely Road, Milton, Cambridge, CB24 6WZ,
ENGLAND Tel: +44 (0)1223 203894

Boost list run by bdawes at, gregod at, cpdaniel at, john at