[nginx] Win32: added per-thread random seeding.
Ruslan Ermilov
ru at nginx.com
Mon Aug 8 08:18:24 UTC 2016
details: http://hg.nginx.org/nginx/rev/09c918460cc6
branches:
changeset: 6649:09c918460cc6
user: Ruslan Ermilov <ru at nginx.com>
date: Thu Aug 04 01:15:41 2016 +0300
description:
Win32: added per-thread random seeding.
The change in b91bcba29351 was not enough to fix random() seeding.
On Windows, the srand() seeds the PRNG only in the current thread,
and worse, is not inherited from the calling thread. Due to this,
worker threads were not properly seeded.
Reported by Marc Bevand.
diffstat:
src/os/win32/ngx_process_cycle.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
diffs (12 lines):
diff -r d43ee392e825 -r 09c918460cc6 src/os/win32/ngx_process_cycle.c
--- a/src/os/win32/ngx_process_cycle.c Tue Jul 26 19:34:12 2016 +0300
+++ b/src/os/win32/ngx_process_cycle.c Thu Aug 04 01:15:41 2016 +0300
@@ -764,6 +764,8 @@ ngx_worker_thread(void *data)
ngx_int_t n;
ngx_cycle_t *cycle;
+ srand((ngx_pid << 16) ^ (unsigned) ngx_time());
+
cycle = (ngx_cycle_t *) ngx_cycle;
for (n = 0; cycle->modules[n]; n++) {
More information about the nginx-devel
mailing list