Skip to content

Commit

Permalink
Fix serialization for RandomDevice. Closes JuliaLang#16451.
Browse files Browse the repository at this point in the history
  • Loading branch information
amitmurthy committed May 31, 2016
1 parent 15626c3 commit 8ae4041
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
3 changes: 2 additions & 1 deletion base/random.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ if is_windows()
else # !windows
immutable RandomDevice <: AbstractRNG
file::IOStream
unlimited::Bool

RandomDevice(unlimited::Bool=true) = new(open(unlimited ? "/dev/urandom" : "/dev/random"))
RandomDevice(unlimited::Bool=true) = new(open(unlimited ? "/dev/urandom" : "/dev/random"), unlimited)
end

rand{ T<:Union{Bool, Base.BitInteger}}(rd::RandomDevice, ::Type{T}) = read( rd.file, T)
Expand Down
10 changes: 10 additions & 0 deletions base/serialize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -895,4 +895,14 @@ function deserialize(s::SerializationState, t::Type{Regex})
Regex(pattern, compile_options, match_options)
end

if !is_windows()
function serialize(s::SerializationState, rd::RandomDevice)
serialize_type(s, typeof(rd))
serialize(s, rd.unlimited)
end
function deserialize(s::SerializationState, t::Type{RandomDevice})
unlimited = deserialize(s)
return RandomDevice(unlimited)
end
end
end
13 changes: 13 additions & 0 deletions test/parallel_exec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -986,3 +986,16 @@ end

# issue #15451
@test remotecall_fetch(x->(y->2y)(x)+1, workers()[1], 3) == 7

# issue #16451
rng=RandomDevice()
retval = @parallel (+) for _ in 1:10
rand(rng)
end
@test retval > 0.0 && retval < 10.0

rand(rng)
retval = @parallel (+) for _ in 1:10
rand(rng)
end
@test retval > 0.0 && retval < 10.0

0 comments on commit 8ae4041

Please sign in to comment.