From e62a16e8f60b7f66418eb2d4084025b98f4c3575 Mon Sep 17 00:00:00 2001 From: Ruslan Ermilov Date: Thu, 4 Aug 2016 01:15:41 +0300 Subject: [PATCH] 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. --- src/os/win32/ngx_process_cycle.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/os/win32/ngx_process_cycle.c b/src/os/win32/ngx_process_cycle.c index 795e41e57..ce2c77d3d 100644 --- a/src/os/win32/ngx_process_cycle.c +++ b/src/os/win32/ngx_process_cycle.c @@ -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++) {