Skip to content

Commit 718f1db

Browse files
committed
undo lock/trylock and use request/tryrequest instead
1 parent 642c26a commit 718f1db

File tree

15 files changed

+81
-33
lines changed

15 files changed

+81
-33
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# News
22

3-
## v1.0.1 - dev
3+
## v1.1.0 - 2023-08-02
44

5-
- Start using `Base`'s API: `lock`, `trylock`, `unlock`, `islocked`, `isready`, `put!`, `take!`. Deprecate `put`, `request`, `release`. Moreover, consider using `take!` instead of `get` (which was not deprecated as it has numerous internal uses).
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`.
67

78
## v1.0.0 - 2023-05-03
89

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.1"
8+
version = "1.1.0"
99

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

benchmark/old_processes_MM1.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ function exp_source(sim::Simulation, lambd::Float64, server::Resource, mu::Float
99
end
1010

1111
function customer(sim::Simulation, server::Resource, mu::Float64)
12-
yield(lock(server))
12+
yield(request(server))
1313
dt = rand(Exponential(1/mu))
1414
yield(timeout(sim, dt))
1515
yield(unlock(server))
1616
end
1717

1818
function customer2(sim::Simulation, server::Resource, mu::Float64)
19-
lock(server) do req
19+
request(server) do req
2020
yield(req)
2121
dt = rand(Exponential(1/mu))
2222
yield(timeout(sim, dt))

benchmark/processes_MM1.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ using ResumableFunctions, ConcurrentSim, Distributions, BenchmarkTools
99
end
1010

1111
@resumable function customer(sim::Simulation, server::Resource, mu::Float64)
12-
@yield lock(server)
12+
@yield request(server)
1313
dt = rand(Exponential(1 / mu))
1414
@yield timeout(sim, dt)
1515
@yield unlock(server)

docs/src/api.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ Private = false
66
```
77

88
```@docs
9-
lock(res::Container; priority::Int=0)
109
unlock(res::Container; priority::Int=0)
11-
trylock(res::Container; priority::Int=0)
1210
take!(sto::Store, filter::Function=get_any_item; priority::Int=0)
1311
```

docs/src/examples/mmc.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ service_dist = Exponential(1 / mu) # service time distribution
2222
@resumable function customer(env::Environment, server::Resource, id::Integer, t_a::Float64, d_s::Distribution)
2323
@yield timeout(env, t_a) # customer arrives
2424
println("Customer $id arrived: ", now(env))
25-
@yield lock(server) # customer starts service
25+
@yield request(server) # customer starts service
2626
println("Customer $id entered service: ", now(env))
2727
@yield timeout(env, rand(d_s)) # server is busy
2828
@yield unlock(server) # customer exits service

docs/src/examples/ross.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const G = Exponential(MU)
4444
else
4545
throw(StopSimulation("No more spares!"))
4646
end
47-
@yield lock(repair_facility)
47+
@yield request(repair_facility)
4848
@yield timeout(env, rand(rng, G))
4949
@yield unlock(repair_facility)
5050
@yield put!(spares, active_process(env))

docs/src/guides/environments.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ julia> isnothing(active_process(sim))
112112
true
113113
```
114114

115-
An exemplary use case for this is the resource system: If a process function calls `lock` to request a `Resource`, the resource determines the requesting process via `active_process`.
115+
An exemplary use case for this is the resource system: If a process function calls `request` to request (lock) a `Resource`, the resource determines the requesting process via `active_process`.
116116

117117
## Miscellaneous
118118

docs/src/tutorial.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ julia> using ConcurrentSim
301301
julia> @resumable function car(env::Environment, name::Int, bcs::Resource, driving_time::Number, charge_duration::Number)
302302
@yield timeout(sim, driving_time)
303303
println(name, " arriving at ", now(env))
304-
@yield lock(bcs)
304+
@yield request(bcs)
305305
println(name, " starting to charge at ", now(env))
306306
@yield timeout(sim, charge_duration)
307307
println(name, " leaving the bcs at ", now(env))
@@ -310,7 +310,7 @@ julia> @resumable function car(env::Environment, name::Int, bcs::Resource, drivi
310310
car (generic function with 1 method)
311311
```
312312

313-
The resource’s `lock` function generates an event that lets you wait until the resource becomes available again. If you are resumed, you “own” the resource until you release it with `unlock`.
313+
The resource’s `request` function generates an event that lets you wait until the resource becomes available again. If you are resumed, you “own” the resource until you release it with `unlock`.
314314

315315
You are responsible to call `unlock` once you are done using the resource. When you unlock (release) a resource, the next waiting process is resumed and now “owns” one of the resource’s slots. The basic `Resource` sorts waiting processes in a FIFO (first in—first out) way.
316316

@@ -324,7 +324,7 @@ DocTestSetup = quote
324324
@resumable function car(env::Environment, name::Int, bcs::Resource, driving_time::Number, charge_duration::Number)
325325
@yield timeout(sim, driving_time)
326326
println(name, " arriving at ", now(env))
327-
@yield lock(bcs)
327+
@yield request(bcs)
328328
println(name, " starting to charge at ", now(env))
329329
@yield timeout(sim, charge_duration)
330330
println(name, " leaving the bcs at ", now(env))
@@ -351,7 +351,7 @@ DocTestSetup = quote
351351
@resumable function car(env::Environment, name::Int, bcs::Resource, driving_time::Number, charge_duration::Number)
352352
@yield timeout(sim, driving_time)
353353
println(name, " arriving at ", now(env))
354-
@yield lock(bcs)
354+
@yield request(bcs)
355355
println(name, " starting to charge at ", now(env))
356356
@yield timeout(sim, charge_duration)
357357
println(name, " leaving the bcs at ", now(env))
@@ -393,7 +393,7 @@ DocTestSetup = quote
393393
@resumable function car(env::Environment, name::Int, bcs::Resource, driving_time::Number, charge_duration::Number)
394394
@yield timeout(sim, driving_time)
395395
println(name, " arriving at ", now(env))
396-
@yield lock(bcs)
396+
@yield request(bcs)
397397
println(name, " starting to charge at ", now(env))
398398
@yield timeout(sim, charge_duration)
399399
println(name, " leaving the bcs at ", now(env))

src/ConcurrentSim.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module ConcurrentSim
1717
export @resumable, @yield
1818
export AbstractProcess, Simulation, run, now, active_process, StopSimulation
1919
export Process, @process, interrupt
20-
export Container, Resource, Store, put!, get, cancel
20+
export Container, Resource, Store, put!, get, cancel, request, tryrequest
2121
export nowDatetime
2222

2323
include("base.jl")

0 commit comments

Comments
 (0)