[Openh323-devel] Bug : PRandom::Number() is not thread-safe with VC++ compiler.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Dear OpenH323 developers,

With VC++ compiler ( and some other compilers), the static object at block scope is not thread-safe.

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
  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
Openh323-devel mailing list

[Open H.323]     [IETF SIP]     [Gnu Gatekeeper]     [Asterisk PBX]     [Fedora Linux]     [Gimp]     [Yosemite News]     [Yosemite Photos]     [Yosemite Campsites]     [ISDN Cause Codes]

Add to Google Powered by Linux