Fix per-thread RNG
This commit is contained in:
parent
5e767e1c38
commit
7ddb2ffb02
@ -34,7 +34,10 @@ public void tomo_init(void)
|
||||
getrandom(&seed, sizeof(seed), 0);
|
||||
srand(seed);
|
||||
srand48(seed);
|
||||
Int$init_random(seed);
|
||||
|
||||
long long_seed;
|
||||
getrandom(&long_seed, sizeof(long_seed), 0);
|
||||
Int$init_random(long_seed);
|
||||
|
||||
if (register_printf_specifier('k', printf_text, printf_text_size))
|
||||
errx(1, "Couldn't set printf specifier");
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user