diff options
author | Ossama Othman <ossama-othman@users.noreply.github.com> | 2007-02-15 20:10:26 +0000 |
---|---|---|
committer | Ossama Othman <ossama-othman@users.noreply.github.com> | 2007-02-15 20:10:26 +0000 |
commit | 56227eb6f605c628f9387750d8a2b5bd0de52ac8 (patch) | |
tree | 33eae6ec3e5b611d7ec67d385c0aa097680d0ba2 | |
parent | 41a908a5c8900a2742c33676875d6bc47e955a2d (diff) | |
download | ATCD-56227eb6f605c628f9387750d8a2b5bd0de52ac8.tar.gz |
ChangeLogTag:Thu Feb 15 20:04:01 UTC 2007 Ossama Othman <ossama_othman at symantec dot com>
-rw-r--r-- | ACE/ChangeLog | 12 | ||||
-rw-r--r-- | ACE/ace/OS_NS_stdlib.cpp | 14 |
2 files changed, 23 insertions, 3 deletions
diff --git a/ACE/ChangeLog b/ACE/ChangeLog index d9a6ef13799..621e6d67569 100644 --- a/ACE/ChangeLog +++ b/ACE/ChangeLog @@ -1,3 +1,15 @@ +Thu Feb 15 20:04:01 UTC 2007 Ossama Othman <ossama_othman at symantec dot com> + + * ace/OS_NS_stdlib.cpp (mkstemp_emulation): + + Include process and thread ID in random number generator seed + value. Addresses problems where the same seed value would end + up being used for different processes and/or threads, resulting + in identical filenames being generated. + + Addressed potential race condition on platforms that do not + inline the value of ACE_Numeric_Limits<>::max(). + Thu Feb 15 17:53:53 UTC 2007 Krishnakumar B <kitty@nospam.invalid.domain> * THANKS: Check-in rules 101: Check-in files that you have diff --git a/ACE/ace/OS_NS_stdlib.cpp b/ACE/ace/OS_NS_stdlib.cpp index cd2005eb041..2874bb2f337 100644 --- a/ACE/ace/OS_NS_stdlib.cpp +++ b/ACE/ace/OS_NS_stdlib.cpp @@ -27,6 +27,7 @@ ACE_RCSID (ace, # include "ace/OS_NS_fcntl.h" # include "ace/OS_NS_ctype.h" # include "ace/OS_NS_sys_time.h" +# include "ace/OS_NS_Thread.h" # include "ace/Numeric_Limits.h" #endif /* ACE_LACKS_MKSTEMP */ @@ -686,7 +687,9 @@ ACE_OS::mkstemp_emulation (ACE_TCHAR * s) static unsigned int const NUM_CHARS = 6; // Do not change! ACE_RANDR_TYPE seed = - static_cast<ACE_RANDR_TYPE> (ACE_OS::gettimeofday ().msec ()); + static_cast<ACE_RANDR_TYPE> (ACE_OS::gettimeofday ().msec ()) + + static_cast<ACE_RANDR_TYPE> (ACE_OS::getpid ()) + + static_cast<ACE_RANDR_TYPE> (ACE_OS::thr_self ()); // We only care about UTF-8 / ASCII characters in generated // filenames. A UTF-16 or UTF-32 character could potentially cause @@ -694,7 +697,12 @@ ACE_OS::mkstemp_emulation (ACE_TCHAR * s) // greatly slowing down this mkstemp() implementation. It is more // practical to limit the search space to UTF-8 / ASCII characters // (i.e. 127 characters). - static float const MAX_VAL = + // + // Note that we can't make this constant static since the compiler + // may not inline the return value of ACE_Numeric_Limits::max(), + // meaning multiple threads could potentially initialize this value + // in parallel. + float const MAX_VAL = static_cast<float> (ACE_Numeric_Limits<char>::max ()); // Use high-order bits rather than low-order ones (e.g. rand() % @@ -706,7 +714,7 @@ ACE_OS::mkstemp_emulation (ACE_TCHAR * s) // e.g.: MAX_VAL * rand() / (RAND_MAX + 1.0) // Factor out the constant coefficient. - static float const coefficient = + float const coefficient = static_cast<float> (MAX_VAL / (RAND_MAX + 1.0f)); // @@ These nested loops may be ineffecient. Improvements are |