diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-11-03 16:21:40 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-11-03 16:21:40 -0500 |
| commit | 7ddb2ffb02f9fff5d78c990165d1008248628c66 (patch) | |
| tree | ed1df19b9a4f05cc44bdcb037cf394ecbaf4b78e /stdlib/threads.c | |
| parent | 5e767e1c387acc0269f449899d8149cdb585495e (diff) | |
Fix per-thread RNG
Diffstat (limited to 'stdlib/threads.c')
| -rw-r--r-- | stdlib/threads.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/stdlib/threads.c b/stdlib/threads.c index 0cb47e1b..beb6771e 100644 --- a/stdlib/threads.c +++ b/stdlib/threads.c @@ -9,6 +9,7 @@ #include <stdlib.h> #include <pthread.h> #include <sys/param.h> +#include <sys/random.h> #include "arrays.h" #include "datatypes.h" @@ -17,10 +18,20 @@ #include "types.h" #include "util.h" +static void *run_thread(Closure_t *closure) +{ + long seed; + getrandom(&seed, sizeof(seed), 0); + Int$init_random(seed); + ((void(*)(void*))closure->fn)(closure->userdata); + return NULL; +} + public Thread_t Thread$new(Closure_t fn) { Thread_t thread = new(pthread_t); - pthread_create(thread, NULL, fn.fn, fn.userdata); + Closure_t *doop = new(Closure_t, .fn=fn.fn, .userdata=fn.userdata); + pthread_create(thread, NULL, (void*)run_thread, doop); return thread; } |
