File tree 1 file changed +9
-7
lines changed
1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -26,9 +26,16 @@ else # !windows
26
26
27
27
rand (rd:: RandomDevice , sp:: SamplerBoolBitInteger ) = read (getfile (rd), sp[])
28
28
29
- getfile (rd:: RandomDevice ) = @inbounds DEV_RANDOM[1 + rd. unlimited]
29
+ function getfile (rd:: RandomDevice )
30
+ devrandom = rd. unlimited ? DEV_URANDOM : DEV_RANDOM
31
+ # TODO : there is a data-race, this can leak up to nthreads() copies of the file descriptors,
32
+ # so use a "thread-once" utility once available
33
+ isassigned (devrandom) || (devrandom[] = open (rd. unlimited ? " /dev/urandom" : " /dev/random" ))
34
+ devrandom[]
35
+ end
30
36
31
- const DEV_RANDOM = IOStream[]
37
+ const DEV_RANDOM = Ref {IOStream} ()
38
+ const DEV_URANDOM = Ref {IOStream} ()
32
39
33
40
end # os-test
34
41
@@ -297,13 +304,8 @@ const THREAD_RNGs = MersenneTwister[]
297
304
end
298
305
return MT
299
306
end
300
-
301
307
function __init__ ()
302
308
resize! (empty! (THREAD_RNGs), Threads. nthreads ()) # ensures that we didn't save a bad object
303
-
304
- if ! Sys. iswindows ()
305
- push! (empty! (DEV_RANDOM), open (" /dev/random" ), open (" /dev/urandom" ))
306
- end
307
309
end
308
310
309
311
You can’t perform that action at this time.
0 commit comments