D5966: Fix race-condition in KRandom-seeding.

René J.V. Bertin noreply at phabricator.kde.org
Wed May 24 21:28:13 UTC 2017


rjvbb added a comment.


  I was going to reflect that it would be better to set `init` in an atomic operation, but:
  
  In https://phabricator.kde.org/D5966#111735, @tfry wrote:
  
  > On further investigation, I see that qsrand() would probably have to be called for //each// thread, in any case.
  
  
  From the qsrand() documentation:
  "The sequence of random numbers generated is deterministic per thread. For example, if two threads call qsrand(1) and subsequently call qrand(), the threads will get the same random number sequence."
  
  That indeed probably means that if only thread 1 calls qsrand(), thread 2 will get the default, unseeded sequence.
  
  > So that would mean keeping track of initialization state in a QThreadStorage<bool>?
  
  Or a simple QSet containing the thread ID, whichever is cheapest?

REPOSITORY
  R244 KCoreAddons

REVISION DETAIL
  https://phabricator.kde.org/D5966

To: tfry, dfaure
Cc: tfry, rjvbb, #frameworks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-frameworks-devel/attachments/20170524/72143fee/attachment.html>


More information about the Kde-frameworks-devel mailing list