Subj : Re: Can C++ local static objects be made thread safe? To : comp.programming.threads From : David Schwartz Date : Wed Feb 09 2005 02:21 pm "Marcin 'Qrczak' Kowalczyk" wrote in message news:871xbp8noz.fsf@qrnik.zagroda... > "David Schwartz" writes: >> IMO, the best way to do this would be with a new language keyword. >> The >> keyword should simply specify that a particular static be initialized at >> startup, rather than lazily. This has the advantage of removing overhead >> rather than adding it. > You don't need a keyword for that - just move the variable outside a > function. So it sounds like you're working on a non-problem. > This has a different problem: uncertainty about relative order of > initialization of variables from different files. Lazy initialization > has other merits besides skipping the initialization if the variable > is not needed at all. If you need precise control over when the constructor is called, it's no trouble to add a lock to that precise control. If you don't need precise control, start it before main when there's only one thread. It sounds like you're working on a non-problem. Most code is going to need to potentially modify the static object anyway. So there will have to be a manual lock because your automatic one will be released too early. DS .