Skip to content

Commit c62a6e5

Browse files
authored
Merge pull request #93 from JuliaDynamics/convenienceinterfaces
introduce unlock, islocked, isready, get! and deprecate get, release
2 parents 91a9809 + 718f1db commit c62a6e5

22 files changed

+404
-68
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# News
22

3+
## v1.1.0 - 2023-08-02
4+
5+
- Start using `Base`'s API: `Base.unlock`, `Base.islocked`, `Base.isready`, `Base.put!`, `Base.take!`. Deprecate `put`, `release`. Moreover, consider using `Base.take!` instead of `Base.get` (which was not deprecated yet, as we decide which semantics to follow). Lastly, `Base.lock` and `Base.trylock` are **not** implement -- they are superficially similar to `request` and `tryrequest`, but have to be explicitly `@yield`-ed.
6+
- Implement `tryrequest` (similar to `Base.trylock`). However, consider also using `Base.isready` and `request` instead of `tryrequest`.
7+
38
## v1.0.0 - 2023-05-03
49

510
- Rename from SimJulia.jl to ConcurrentSim.jl

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ license = "MIT"
55
desc = "A discrete event process oriented simulation framework."
66
authors = ["Ben Lauwens and SimJulia and ConcurrentSim contributors"]
77
repo = "https://github.com/JuliaDynamics/ConcurrentSim.jl.git"
8-
version = "1.0.0"
8+
version = "1.1.0"
99

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

benchmark/old_processes_MM1.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function customer(sim::Simulation, server::Resource, mu::Float64)
1212
yield(request(server))
1313
dt = rand(Exponential(1/mu))
1414
yield(timeout(sim, dt))
15-
yield(release(server))
15+
yield(unlock(server))
1616
end
1717

1818
function customer2(sim::Simulation, server::Resource, mu::Float64)

benchmark/processes_MM1.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ end
1212
@yield request(server)
1313
dt = rand(Exponential(1 / mu))
1414
@yield timeout(sim, dt)
15-
@yield release(server)
15+
@yield unlock(server)
1616
end
1717

1818
function test_mm1(n::Float64)

docs/Project.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
[deps]
2+
ConcurrentSim = "6ed1e86c-fcaf-46a9-97e0-2b26a2cdb499"
3+
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
24
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
35
ResumableFunctions = "c5292f4c-5179-55e1-98c5-05642aab7184"
6+
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
7+
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"

docs/make.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
using Revise
12
using Documenter
23
using ResumableFunctions
34
using ConcurrentSim
45

6+
DocMeta.setdocmeta!(ConcurrentSim, :DocTestSetup, :(using ConcurrentSim, ResumableFunctions); recursive=true)
7+
58
makedocs(
69
sitename = "ConcurrentSim",
710
authors = "Ben Lauwens and SimJulia & ConcurrentSim contributors",
11+
strict = true,
12+
doctest = false,
813
pages = [
914
"Home" => "index.md",
1015
"Tutorial" => "tutorial.md",

docs/src/api.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,9 @@
33
```@autodocs
44
Modules = [ConcurrentSim]
55
Private = false
6+
```
7+
8+
```@docs
9+
unlock(res::Container; priority::Int=0)
10+
take!(sto::Store, filter::Function=get_any_item; priority::Int=0)
611
```

docs/src/examples/Latency.md

Lines changed: 58 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,32 @@ In this example we show how to separate the time delay between processes from th
77
### Load Packages
88

99

10-
```julia
10+
```jldoctest 1; output = false
1111
using ConcurrentSim
1212
using ResumableFunctions
13-
import ConcurrentSim.put
14-
import Base.get
13+
import Base: put!, take!
14+
15+
# output
1516
```
1617

1718
### Define Constants
1819

1920

20-
```julia
21-
srand(8710) # set random number seed for reproducibility
21+
```jldoctest 1; output = false
2222
const SIM_DURATION = 100.
2323
const SEND_PERIOD = 5.0
2424
const RECEIVE_PERIOD = 3.0;
25+
26+
nothing # hide
27+
28+
# output
2529
```
2630

2731
### Define Cable model
2832
The `Cable` contains reference to the simulation it is part of, the delay that messages experience, and a store that contains the sent messages
2933

3034

31-
```julia
35+
```jldoctest 1; output = false
3236
mutable struct Cable
3337
env::Simulation
3438
delay::Float64
@@ -38,79 +42,96 @@ mutable struct Cable
3842
return new(env, delay, Store{String}(env))
3943
end
4044
end;
45+
46+
nothing # hide
47+
48+
# output
4149
```
4250

4351
The latency function is a generator which yields two events: first a `timeout` that represents the transmission delay, then a put event when the message gets stored in the store.
4452

4553

46-
```julia
54+
```jldoctest 1; output = false
4755
@resumable function latency(env::Simulation, cable::Cable, value::String)
4856
@yield timeout(cable.env, cable.delay)
49-
@yield put(cable.store, value)
50-
end;
57+
@yield put!(cable.store, value)
58+
end;
59+
60+
nothing # hide
61+
62+
# output
5163
```
5264

53-
The `put` and `get` functions allow interaction with the cable (note that these are not `@resumable` because they need to return the result of the operation and not the operation itself).
65+
The `put!` and `take!` functions allow interaction with the cable (note that these are not `@resumable` because they need to return the result of the operation and not the operation itself).
5466

5567

56-
```julia
57-
function put(cable::Cable, value::String)
68+
```jldoctest 1; output = false
69+
function put!(cable::Cable, value::String)
5870
@process latency(cable.env, cable, value) # results in the scheduling of all events generated by latency
5971
end
6072
61-
function get(cable::Cable)
62-
get(cable.store) # returns an element stored in the cable store
73+
function take!(cable::Cable); output = false
74+
take!(cable.store) # returns an element stored in the cable store
6375
end;
76+
77+
nothing # hide
78+
79+
# output
6480
```
6581

6682
The `sender` and `receiver` generators yield events to the simulator.
6783

6884

69-
```julia
85+
```jldoctest 1; output = false
7086
@resumable function sender(env::Simulation, cable::Cable)
7187
while true
7288
@yield timeout(env, SEND_PERIOD)
7389
value = "sender sent this at $(now(env))"
74-
put(cable, value)
90+
put!(cable, value)
7591
end
7692
end
7793
7894
@resumable function receiver(env::Simulation, cable::Cable)
7995
while true
8096
@yield timeout(env, RECEIVE_PERIOD)
81-
msg = @yield get(cable)
97+
msg = @yield take!(cable)
8298
println("Received this at $(now(env)) while $msg")
8399
end
84100
end;
101+
102+
nothing # hide
103+
104+
# output
85105
```
86106

87107
Create simulation, register events, and run!
88108

89109

90-
```julia
110+
```jldoctest 1
91111
env = Simulation()
92112
cable = Cable(env, 10.)
93113
@process sender(env, cable)
94114
@process receiver(env, cable)
95115
96116
run(env, SIM_DURATION)
97-
```
98-
99-
Received this at 15.0 while sender sent this at 5.0
100-
Received this at 20.0 while sender sent this at 10.0
101-
Received this at 25.0 while sender sent this at 15.0
102-
Received this at 30.0 while sender sent this at 20.0
103-
Received this at 35.0 while sender sent this at 25.0
104-
Received this at 40.0 while sender sent this at 30.0
105-
Received this at 45.0 while sender sent this at 35.0
106-
Received this at 50.0 while sender sent this at 40.0
107-
Received this at 55.0 while sender sent this at 45.0
108-
Received this at 60.0 while sender sent this at 50.0
109-
Received this at 65.0 while sender sent this at 55.0
110-
Received this at 70.0 while sender sent this at 60.0
111-
Received this at 75.0 while sender sent this at 65.0
112-
Received this at 80.0 while sender sent this at 70.0
113-
Received this at 85.0 while sender sent this at 75.0
114-
Received this at 90.0 while sender sent this at 80.0
115-
Received this at 95.0 while sender sent this at 85.0
116117
118+
# output
119+
120+
Received this at 15.0 while sender sent this at 5.0
121+
Received this at 20.0 while sender sent this at 10.0
122+
Received this at 25.0 while sender sent this at 15.0
123+
Received this at 30.0 while sender sent this at 20.0
124+
Received this at 35.0 while sender sent this at 25.0
125+
Received this at 40.0 while sender sent this at 30.0
126+
Received this at 45.0 while sender sent this at 35.0
127+
Received this at 50.0 while sender sent this at 40.0
128+
Received this at 55.0 while sender sent this at 45.0
129+
Received this at 60.0 while sender sent this at 50.0
130+
Received this at 65.0 while sender sent this at 55.0
131+
Received this at 70.0 while sender sent this at 60.0
132+
Received this at 75.0 while sender sent this at 65.0
133+
Received this at 80.0 while sender sent this at 70.0
134+
Received this at 85.0 while sender sent this at 75.0
135+
Received this at 90.0 while sender sent this at 80.0
136+
Received this at 95.0 while sender sent this at 85.0
137+
```

docs/src/examples/mmc.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ service_dist = Exponential(1 / mu) # service time distribution
2525
@yield request(server) # customer starts service
2626
println("Customer $id entered service: ", now(env))
2727
@yield timeout(env, rand(d_s)) # server is busy
28-
@yield release(server) # customer exits service
28+
@yield unlock(server) # customer exits service
2929
println("Customer $id exited service: ", now(env))
3030
end
3131

docs/src/examples/ross.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const G = Exponential(MU)
3737
while true
3838
try @yield timeout(env, Inf) catch end
3939
@yield timeout(env, rand(rng, F))
40-
get_spare = get(spares)
40+
get_spare = take!(spares)
4141
@yield get_spare | timeout(env)
4242
if state(get_spare) != ConcurrentSim.idle
4343
@yield interrupt(value(get_spare))
@@ -46,8 +46,8 @@ const G = Exponential(MU)
4646
end
4747
@yield request(repair_facility)
4848
@yield timeout(env, rand(rng, G))
49-
@yield release(repair_facility)
50-
@yield put(spares, active_process(env))
49+
@yield unlock(repair_facility)
50+
@yield put!(spares, active_process(env))
5151
end
5252
end
5353
@@ -58,7 +58,7 @@ end
5858
end
5959
for i in 1:S
6060
proc = @process machine(env, repair_facility, spares)
61-
@yield put(spares, proc)
61+
@yield put!(spares, proc)
6262
end
6363
end
6464

0 commit comments

Comments
 (0)