From: Robert J. <rob...@bi...> - 2008-08-19 08:43:24
|
OK, fixed in trunk. Why it was that way for RTEMS and not every other platform is beyond me! Robert Jongbloed OPAL/OpenH323 Architect and Co-founder. > -----Original Message----- > From: ope...@li... [mailto:openh323- > dev...@li...] On Behalf Of Thien Nguyen > Sent: Tuesday, 19 August 2008 6:03 PM > To: ope...@li... > Subject: [Openh323-devel] Bug : PRandom::Number() is not thread-safe > with VC++ compiler. > > Dear OpenH323 developers, > > With VC++ compiler ( and some other compilers), the static object at > block scope is not thread-safe. > > http://blogs.msdn.com/oldnewthing/archive/2004/03/08/85901.aspx > > > Therefore, the following method is not thread-safe. > > // pwlib/src/ptclib/random.cxx > > unsigned PRandom::Number() > { > #ifndef P_RTEMS > static PMutex mutex; // <-- not thread-safe > #endif > PWaitAndSignal wait(mutex); > > static PRandom rand; > return rand; > } > > Here is a "error" scenario : > > a. First thread comes and try to initialize the static object > "PMutex mutex" but not finish this task. > > b. Second thread comes and thinks that the static object PMutex > mutex was initialize. Therefore, it excecutes "PWaitAndSignal > wait(mutex)" : bug will happen because the mutex is not completely > initialized. > > Suggestion : move "static PMutex mutex;" into file scope. > > Thank for reading. > > > > --------------------------------------------------------------------- > ---- > This SF.Net email is sponsored by the Moblin Your Move Developer's > challenge > Build the coolest Linux based applications with Moblin SDK & win > great prizes > Grand prize is a trip for two to an Open Source event anywhere in the > world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > Openh323-devel mailing list > Ope...@li... > https://lists.sourceforge.net/lists/listinfo/openh323-devel |