D5966: Fix race-condition in KRandom-seeding.

Thomas Friedrichsmeier noreply at phabricator.kde.org
Thu May 25 08:33:20 UTC 2017


tfry updated this revision to Diff 14831.
tfry added a comment.


  Ensure proper per-thread random-seeding in KRandom::random().
  
  As commented, the problem is somewhat different, than I though, originally:
  
  qsrand() and qrand() keep random seeds per QThread, and each thread needs a separate call
  to qsrand(). Without this patch, qsrand() would only be called for the first thread to call
  KRandom::random(). Any other thread will effectively use qsrand(1).
  
  Note that prior to https://phabricator.kde.org/R244:9ae6d765b37135bbfe3a8b936e5a88b8a435e424 srand() and rand() were used.
  Those are not properly thread-safe, but at least this would not result in threads using a
  fixed seed.

REPOSITORY
  R244 KCoreAddons

CHANGES SINCE LAST UPDATE
  https://phabricator.kde.org/D5966?vs=14824&id=14831

BRANCH
  master

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

AFFECTED FILES
  src/lib/randomness/krandom.cpp

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


More information about the Kde-frameworks-devel mailing list