diff options
| author | Garrett D'Amore <garrett@damore.org> | 2016-12-25 09:03:15 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2016-12-25 09:03:15 -0800 |
| commit | 8cc1596706dfdd0dd62e8ea0db1501a79fd7c2e9 (patch) | |
| tree | 0dacd618d15f3f405d1a566fcbb12c7b337459a8 /src/platform/posix | |
| parent | 94d8246071dd149bdcfde6db8d2b6c7d2379ad31 (diff) | |
| download | nng-8cc1596706dfdd0dd62e8ea0db1501a79fd7c2e9.tar.gz nng-8cc1596706dfdd0dd62e8ea0db1501a79fd7c2e9.tar.bz2 nng-8cc1596706dfdd0dd62e8ea0db1501a79fd7c2e9.zip | |
Mix the PID into our random number seed.
Diffstat (limited to 'src/platform/posix')
| -rw-r--r-- | src/platform/posix/posix_thread.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/platform/posix/posix_thread.c b/src/platform/posix/posix_thread.c index 00dc8589..3fd9bfe7 100644 --- a/src/platform/posix/posix_thread.c +++ b/src/platform/posix/posix_thread.c @@ -17,6 +17,8 @@ #include <time.h> #include <string.h> #include <stdlib.h> +#include <sys/types.h> +#include <unistd.h> struct nni_thread { pthread_t tid; @@ -139,10 +141,14 @@ nni_plat_init(int (*helper)(void)) while (nni_plat_next == 0) { uint16_t xsub[3]; nni_time now = nni_clock(); + pid_t pid = getpid(); xsub[0] = (uint16_t) now; xsub[1] = (uint16_t) (now >> 16); xsub[2] = (uint16_t) (now >> 24); + xsub[0] ^= (uint16_t) pid; + xsub[1] ^= (uint16_t) (pid >> 16); + xsub[2] ^= (uint16_t) (pid >> 24); nni_plat_next = nrand48(xsub); } #endif |
