Subj : Re: Can C++ local static objects be made thread safe? To : comp.programming.threads From : Gianni Mariani Date : Wed Jan 19 2005 07:31 am Alexander Terekhov wrote: > Gianni Mariani wrote: > [...] > >>I don't think so. Having heard the growlings of a colleague recently, I >>suspect there are at least 2 people that violently disagree with you. >> >>Do explain what you think is so silly. > > > "You should not pay for what you don't use" motto, you know. For > mutable static locals, you must synchronize operations (I mean > apart from init) anyway. So, apart from mutable static locals > atomic<>"-ized internally, you better simply stick to some lock > (e.g. POSIX's statically initialized mutex or rwlock) for both > init and subsequent operations on "threads unaware" static local. > That's just one example where compiler synchronized static local > is totally useless. Since this synchronization overhead is performed exactly once per static local and the number of static locals is usually very limited (and by defintiion cannot exceed the some factor multiple of the size of the code, the overhead is probably so negligible that the cost of potential errors by far exceeds the benefits of the "not pay for" motto. By the number of people I know of that are bitten by this issue, this is a significant problem and solving it once and for all is "The Way To Go"(TM) .