From: Benoît L. <ne...@pg...> - 2008-05-05 18:30:25
|
Le vendredi 02 mai 2008 à 10:34 +0200, Tim Moore a écrit : > This concern is valid, but *every* use of SGMutex removed in Benôit's patch is > not actually thread safe now! Static local variables are initialized the first > time a function is called. I'm not sure if the proper lesson to take away is > that threading is hard, because of subtle issues like this, or if it's easy, > because it works even in the presence of such bugs ;) I looked at the code again and, if I understand your warning, there is 2 options: 1/ I'm completely dumb (which is possible ;)) 2/ The old code was not thread safe either. Old code static SGMutex mutex; ------ New code static OpenThreads::Mutex mutex; ------ As a side note, it seems you already use OpenThreads Mutexes in various places, like in line 939 of simgear/scene/model/animation.cxx: OpenThreads::ScopedLock<OpenThreads::Mutex> lock(normalizeMutex); or in line 72 of simgear/scene/util/StateAttributeFactory.cxx: OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_instanceMutex); Would this produce the correct behavior ? Regards, Benoît |