tfry created this revision. Restricted Application added a project: Frameworks. Restricted Application added a subscriber: Frameworks.
REVISION SUMMARY Consider the following scenario: Thread A calls KRandom::random(), for the first time. It will now go through a (relatively) expensive procedure to seed the RNG. Note that before this patch, "init" is set to true long _before_ the actual call to qsrand(). Now, thread B calls KRandom::random() in this sensitive time window. Since it finds "init" to be true, it will skip over the expensive initialization, and be very likely to arrive at qrand(), before thread A had a chance to call qsrand(). This patch is the simplest possible solution: Making sure init is set, _after_ the seed was really initialized. This does not prevent init races, but the worst case scenario is now, that several threads are each going through the seeding. A more elaborate solution would be to add mutex-protection during initialization. REPOSITORY R244 KCoreAddons BRANCH master REVISION DETAIL https://phabricator.kde.org/D5966 AFFECTED FILES src/lib/randomness/krandom.cpp To: tfry, dfaure Cc: tfry, rjvbb, #frameworks