From f77f8fbd5d0d38745e87527a7cfa55f04f1ea1fb Mon Sep 17 00:00:00 2001 From: Gabriel Baraldi Date: Wed, 21 Dec 2022 16:02:59 -0300 Subject: [PATCH 1/2] Initialize the rng of external threads with jl_rand() --- src/threading.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/threading.c b/src/threading.c index c45143f0d01ca..d7104bbcc5d7a 100644 --- a/src/threading.c +++ b/src/threading.c @@ -413,6 +413,9 @@ JL_DLLEXPORT jl_gcframe_t **jl_adopt_thread(void) // warning: this changes `jl_current_task`, so be careful not to call that from this function jl_task_t *ct = jl_init_root_task(ptls, stack_lo, stack_hi); JL_GC_PROMISE_ROOTED(ct); + for (size_t i = 0; i < 4 ; i++) { + ct->rngState[i] = jl_rand(); + } return &ct->gcstack; } From ab80c82075b148fb03bd91879a7aa998f527d256 Mon Sep 17 00:00:00 2001 From: Gabriel Baraldi Date: Wed, 21 Dec 2022 16:12:33 -0300 Subject: [PATCH 2/2] Use uv_random since it's safer --- src/threading.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/threading.c b/src/threading.c index d7104bbcc5d7a..150fbacbc421b 100644 --- a/src/threading.c +++ b/src/threading.c @@ -413,10 +413,7 @@ JL_DLLEXPORT jl_gcframe_t **jl_adopt_thread(void) // warning: this changes `jl_current_task`, so be careful not to call that from this function jl_task_t *ct = jl_init_root_task(ptls, stack_lo, stack_hi); JL_GC_PROMISE_ROOTED(ct); - for (size_t i = 0; i < 4 ; i++) { - ct->rngState[i] = jl_rand(); - } - + uv_random(NULL, NULL, &ct->rngState, sizeof(ct->rngState), 0, NULL); return &ct->gcstack; }