Skip to content

Commit feeb732

Browse files
committed
fix error with rand()
reported in issue #31
1 parent a00a53d commit feeb732

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "DiscreteEvents"
22
uuid = "127e53a7-d08a-4bd9-afb0-daf0d2b65a85"
33
authors = ["Paul Bayer <Paul.Bayer@gleichsam.de>"]
4-
version = "0.3.3"
4+
version = "0.3.4"
55

66
[deps]
77
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"

src/DiscreteEvents.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pkg> add("https://github.com/pbayer/DiscreteEvents.jl")
2727
module DiscreteEvents
2828

2929
"Gives the package version."
30-
const version = v"0.3.3"
30+
const version = v"0.3.4"
3131

3232
using Unitful, Random, DataStructures, Logging, .Threads, Distributions
3333
import Unitful: FreeUnits, Time

src/schedule.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ periodic!(rtc::RTClock, ex::T) where T<:Action = _assign(rtc, Sample(ex))
209209
# Return a random number out of the thread ids of all available parallel clocks
210210
function _spawnid(c::Clock)
211211
if c.id == 1
212-
return ifelse(isempty(c.ac), 1, rand(rng, 1:(length(c.ac)+1)))
212+
return isempty(c.ac) ? 1 : rand(rng, 1:(length(c.ac)+1))
213213
elseif isempty(c.ac)
214214
return c.id
215215
else
@@ -221,21 +221,21 @@ _spawnid(ac::ActiveClock) = _spawnid(ac.master[])
221221
# return a valid clock id
222222
function _cid(c::Clock, cid::Int, spawn::Bool)
223223
if c.id == cid
224-
return ifelse(spawn, _spawnid(c), cid)
224+
return spawn ? _spawnid(c) : cid
225225
elseif c.id == 1
226226
isempty(c.ac) && return 1
227227
cid (eachindex(c.ac).+1) && return cid
228-
return ifelse(spawn, _spawnid(c), 1)
228+
return spawn ? _spawnid(c) : 1
229229
else
230230
_cid(c.ac[], cid, spawn)
231231
end
232232
end
233233
function _cid(ac::ActiveClock, cid::Int, spawn::Bool)
234234
if ac.id == cid
235-
return ifelse(spawn, _spawnid(ac.master[]), cid)
235+
return spawn ? _spawnid(ac.master[]) : cid
236236
else
237237
cid 1:(length(ac.master[].ac).+1) && return cid
238-
return ifelse(spawn, _spawnid(ac.master[]), ac.id)
238+
return spawn ? _spawnid(ac.master[]) : ac.id
239239
end
240240
end
241241
_cid(rtc::RTClock, cid::Int, spawn::Bool) = rtc.id

test/test_threads.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ clk = Clock()
1313
if VERSION v"1.3"
1414
if nthreads() > 1
1515
include("test_threads1.jl")
16-
# include("test_threads2.jl")
16+
include("test_threads2.jl")
1717
else
1818
@test_warn "no parallel threads available!" fork!(clk)
1919
end

0 commit comments

Comments
 (0)