Subj : Re: Can C++ local static objects be made thread safe? To : comp.programming.threads From : gniccolai Date : Thu Feb 10 2005 06:50 am Marcin 'Qrczak' Kowalczyk wrote in message > > > I hope that this explain why mutex applied to "code section" are > > basically wrong: mutex are meant to guard data access on a data set. > > It guards the object during its initialization. No. It guards object initialization, which includes some data locking. > Ok, in rare cases where your classes are so poorly mapped to the > problem domain that it doesn't work (is there a practical such case?) > you must add some other synchronization. But synchronizing > initialization of static locals never hurts: It's not a question of poor mapping, because you may wish to have some threads accessing part of a class and part of another with the same mutex constraints; and this is legal (a different approach, the one that you think is "good mapping", has been tried with the synchronized keyword in the early Java, with disastrous results. Luckily, latest versions of Java and .NET made it right). > > Fortunately compilers don't care about luck, they only care about But you should. The "luck" in threads means the fact that if there is a probablility of 1/10000000 that something is wrong you get an error in a second or so. That is what I say when "luck". If you want to have your programs work in MT you (and not the compiler, that can't guess what you want to do) MUST not rely on luck, and do correct things. Misusing things is not doing correct things, and brings bad luck. Which means a fault in a reasonable time. > > 1) Demonstrate that the thing is an EXISTING problem. That is, > > demonstrate that the average threaded program does static > > initialization wrong (because the average programmer needs the help > > of the compiler). > > I have shown the read_unicode_database_from_file example. A piece of > code written with no MT in mind will work in MT with my semantics and > will not work with your semantics. This is not a demonstartion. And that was not a problem. > > I don't have a more real-life examples because I avoid C++ as a plague. I can understand now. I am sorry, but it really seem that you have not enough experience in both C++ and threading to treat the argument seriously. Moreover, you refuse to accept simple facts and definitions that are absolutely well known to even newbies here. Sorry, but I'll treat the rest of your post and every other post from you as irrilevant. Giancarlo. .