Skip to content

Commit

Permalink
deprecate ConcurrentSim.release in favor of Base.unlock
Browse files Browse the repository at this point in the history
  • Loading branch information
Krastanov committed Jul 28, 2023
1 parent 5827540 commit 3410a36
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion benchmark/old_processes_MM1.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function customer(sim::Simulation, server::Resource, mu::Float64)
yield(lock(server))
dt = rand(Exponential(1/mu))
yield(timeout(sim, dt))
yield(release(server))
yield(unlock(server))
end

function customer2(sim::Simulation, server::Resource, mu::Float64)
Expand Down
2 changes: 1 addition & 1 deletion benchmark/processes_MM1.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ end
@yield lock(server)
dt = rand(Exponential(1 / mu))
@yield timeout(sim, dt)
@yield release(server)
@yield unlock(server)
end

function test_mm1(n::Float64)
Expand Down
2 changes: 1 addition & 1 deletion docs/src/examples/mmc.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ service_dist = Exponential(1 / mu) # service time distribution
@yield lock(server) # customer starts service
println("Customer $id entered service: ", now(env))
@yield timeout(env, rand(d_s)) # server is busy
@yield release(server) # customer exits service
@yield unlock(server) # customer exits service
println("Customer $id exited service: ", now(env))
end

Expand Down
2 changes: 1 addition & 1 deletion docs/src/examples/ross.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const G = Exponential(MU)
end
@yield lock(repair_facility)
@yield timeout(env, rand(rng, G))
@yield release(repair_facility)
@yield unlock(repair_facility)
@yield put!(spares, active_process(env))
end
end
Expand Down
12 changes: 6 additions & 6 deletions docs/src/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,14 +305,14 @@ julia> @resumable function car(env::Environment, name::Int, bcs::Resource, drivi
println(name, " starting to charge at ", now(env))
@yield timeout(sim, charge_duration)
println(name, " leaving the bcs at ", now(env))
@yield release(bcs)
@yield unlock(bcs)
end
car (generic function with 1 method)
```

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.
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`.

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.
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.

A resource needs a reference to an `Environment` and a capacity when it is created:

Expand All @@ -328,7 +328,7 @@ DocTestSetup = quote
println(name, " starting to charge at ", now(env))
@yield timeout(sim, charge_duration)
println(name, " leaving the bcs at ", now(env))
@yield release(bcs)
@yield unlock(bcs)
end
end
```
Expand All @@ -355,7 +355,7 @@ DocTestSetup = quote
println(name, " starting to charge at ", now(env))
@yield timeout(sim, charge_duration)
println(name, " leaving the bcs at ", now(env))
@yield release(bcs)
@yield unlock(bcs)
end
sim = Simulation()
Expand Down Expand Up @@ -397,7 +397,7 @@ DocTestSetup = quote
println(name, " starting to charge at ", now(env))
@yield timeout(sim, charge_duration)
println(name, " leaving the bcs at ", now(env))
@yield release(bcs)
@yield unlock(bcs)
end
sim = Simulation()
Expand Down
2 changes: 1 addition & 1 deletion src/ConcurrentSim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module ConcurrentSim
export @resumable, @yield
export AbstractProcess, Simulation, run, now, active_process, StopSimulation
export Process, @process, interrupt
export Container, Resource, Store, put!, get, release, cancel
export Container, Resource, Store, put!, get, cancel
export nowDatetime

include("base.jl")
Expand Down
1 change: 1 addition & 0 deletions src/deprecated.jl
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Base.@deprecate put(args...) put!(args...)
Base.@deprecate request(args...; kwargs...) lock(args...; kwargs...)
Base.@deprecate release(args...; kwargs...) unlock(args...; kwargs...)
4 changes: 1 addition & 3 deletions src/resources/containers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function get(con::Container{N}, amount::N; priority::Int=0) where N<:Real
get_ev
end

release(res::Resource; priority::Int=0) = get(res, 1; priority=priority)
unlock(res::Resource; priority::Int=0) = get(res, 1; priority=priority)

function do_put(con::Container{N}, put_ev::Put, key::ContainerKey{N}) where N<:Real
con.level + key.amount > con.capacity && return false
Expand Down Expand Up @@ -88,5 +88,3 @@ true
```
"""
islocked(c::Container) = c.level==c.capacity

unlock(c::Container) = release(c)
2 changes: 1 addition & 1 deletion test/test_resources_containers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ using ResumableFunctions
println("$(now(sim)), client $i is being served")
@yield timeout(sim, rand())
println("$(now(sim)), client $i has been served")
@yield release(res)
@yield unlock(res)
end

@resumable function generate(sim::Simulation, res::Resource)
Expand Down

0 comments on commit 3410a36

Please sign in to comment.