Skip to content

Commit 5827540

Browse files
committed
deprecate ConcurrentSim.requests in favor of Base.lock
1 parent c6dcb9a commit 5827540

13 files changed

+82
-40
lines changed

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(request(server))
12+
yield(lock(server))
1313
dt = rand(Exponential(1/mu))
1414
yield(timeout(sim, dt))
1515
yield(release(server))
1616
end
1717

1818
function customer2(sim::Simulation, server::Resource, mu::Float64)
19-
request(server) do req
19+
lock(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 request(server)
12+
@yield lock(server)
1313
dt = rand(Exponential(1 / mu))
1414
@yield timeout(sim, dt)
1515
@yield release(server)

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 request(server) # customer starts service
25+
@yield lock(server) # customer starts service
2626
println("Customer $id entered service: ", now(env))
2727
@yield timeout(env, rand(d_s)) # server is busy
2828
@yield release(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 request(repair_facility)
47+
@yield lock(repair_facility)
4848
@yield timeout(env, rand(rng, G))
4949
@yield release(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 `request` 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 `lock` to request a `Resource`, the resource determines the requesting process via `active_process`.
116116

117117
## Miscellaneous
118118

docs/src/tutorial.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ In this section, we’ll briefly introduce ConcurrentSim’s `Resource` class.
291291

292292
We’ll slightly modify our electric vehicle process `car` that we introduced in the last sections.
293293

294-
The car will now drive to a battery charging station (BCS) and request one of its two charging spots. If both of these spots are currently in use, it waits until one of them becomes available again. It then starts charging its battery and leaves the station afterwards:
294+
The car will now drive to a battery charging station (BCS) and request (lock) one of its two charging spots. If both of these spots are currently in use, it waits until one of them becomes available again. It then starts charging its battery and leaves the station afterwards:
295295

296296
```jldoctest
297297
julia> using ResumableFunctions
@@ -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 request(bcs)
304+
@yield lock(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 `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.
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.
314314

315315
You are responsible to call `release` once you are done using the resource. When you 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 request(bcs)
327+
@yield lock(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 request(bcs)
354+
@yield lock(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 request(bcs)
396+
@yield lock(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, request, release, cancel
20+
export Container, Resource, Store, put!, get, release, cancel
2121
export nowDatetime
2222

2323
include("base.jl")

src/deprecated.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
Base.@deprecate put(args...) put!(args...)
2+
Base.@deprecate request(args...; kwargs...) lock(args...; kwargs...)

src/resources/containers.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function put!(con::Container{N}, amount::N; priority::Int=0) where N<:Real
3030
put_ev
3131
end
3232

33-
request(res::Resource; priority::Int=0) = put!(res, 1; priority=priority)
33+
lock(res::Resource; priority::Int=0) = put!(res, 1; priority=priority)
3434

3535
function get(con::Container{N}, amount::N; priority::Int=0) where N<:Real
3636
get_ev = Get(con.env)
@@ -65,7 +65,7 @@ Returns `true` if the Container is not empty, similarly to the meaning of `isrea
6565
julia> sim = Simulation(); res = Resource(sim); isready(res)
6666
false
6767
68-
julia> request(res); isready(res)
68+
julia> lock(res); isready(res)
6969
true
7070
```
7171
"""
@@ -80,14 +80,13 @@ Returns `true` if the store is full, similarly to the meaning of `islocked` for
8080
julia> sim = Simulation(); res = Resource(sim, 2); islocked(res)
8181
false
8282
83-
julia> request(res); islocked(res)
83+
julia> lock(res); islocked(res)
8484
false
8585
86-
julia> request(res); islocked(res)
86+
julia> lock(res); islocked(res)
8787
true
8888
```
8989
"""
9090
islocked(c::Container) = c.level==c.capacity
9191

9292
unlock(c::Container) = release(c)
93-
lock(c::Container) = request(c)

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ println("Starting tests with $(Threads.nthreads()) threads out of `Sys.CPU_THREA
3232
@doset "simulations"
3333
@doset "processes"
3434
@doset "resources_containers"
35+
@doset "resources_containers_deprecated"
3536
@doset "resources_stores"
3637
@doset "utils_time"
3738
VERSION >= v"1.9" && @doset "doctests"

0 commit comments

Comments
 (0)