Subj : Re: Can C++ local static objects be made thread safe? To : comp.programming.threads From : David Hopwood Date : Sun Feb 20 2005 05:02 am Giancarlo Niccolai wrote: > David Hopwood wrote: >>Giancarlo Niccolai wrote: >>>Marcin 'Qrczak' Kowalczyk wrote in message news:<87acq3h3vd.fsf@qrnik.zagroda>... >>>> 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 previous >>>> 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, I didn't mean HOW I may access the variable. I meant WHEN. I > din't say that access must not be guarded somehow (i.e. BY MYSELF), I > wrote that I may try the access at ANY MOMENT. I've restored the context of Marcin's article that you were replying to. It is clear from the quoted section of POSIX that your response to that article was wrong: there *are* restrictions on when memory locations may be accessed. (There are additional restrictions in the C++ standard.) > P.s. BTW, you didn't cite the part of the article that says: > > ---- > Applications may allow more than one thread of control to read a > memory location simultaneously. Because it's not relevant. -- David Hopwood .