
----Original Message---- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] 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 Martin.Bonner@Pitechnology.com Pi Technology, Milton Hall, Ely Road, Milton, Cambridge, CB24 6WZ, ENGLAND Tel: +44 (0)1223 203894