]> git.kaiwu.me - nginx.git/commitdiff
Win32: added per-thread random seeding.
authorRuslan Ermilov <ru@nginx.com>
Wed, 3 Aug 2016 22:15:41 +0000 (01:15 +0300)
committerRuslan Ermilov <ru@nginx.com>
Wed, 3 Aug 2016 22:15:41 +0000 (01:15 +0300)
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

index 795e41e57a4017a77806a7e1ba5223cd6afc61f5..ce2c77d3d29a52af0d74cece68771b5dafac8e7b 100644 (file)
@@ -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++) {