Subj : Re: Can C++ local static objects be made thread safe? To : comp.programming.threads From : David Hopwood Date : Sat Feb 19 2005 05:58 pm Giancarlo Niccolai wrote: > Marcin 'Qrczak' Kowalczyk wrote in message news:<87acq3h3vd.fsf@qrnik.zagroda>... >>gniccolai@yahoo.com (Giancarlo Niccolai) writes: > >>If a program waits on an automatically inserted mutex, this means that >>the initialization of a static local is in progress (because the mutex >>is locked only during such initialization) and that a thread tries to >>execute this definition again. This is prohibited by current C++, you >>may not enter initialization of a static local before its brevious >>initialization has completed, the program is already broken. > > I can try to access any variable from any thread in any moment, in C, > in C++, or in any language, and there's nothing in the C++ or posix > standards preventing me from doing it. # Applications shall ensure that access to any memory location by more than # one thread of control (threads or processes) is restricted such that no # thread of control can read or modify a memory location while another # thread of control may be modifying it. (This is strictly speaking for C rather than C++, but if a threading model were defined for C++ it would presumably have the same restriction. Of course this doesn't actually *prevent* you from performing such an access, but it has undefined behaviour in POSIX.) -- David Hopwood .