ConcurrentSim.ConcurrentSim
— ModuleMain module for ConcurrentSim.jl – a discrete event process oriented simulation framework for Julia.
ConcurrentSim.Container
— TypeContainer{N}(env::Environment, capacity::N=one(N); level::N=zero(N))
A "Container" resource object, storing up to capacity
units of a resource (of type N
).
There is a Resource
alias for Container{Int}
.
Resource()
with default capacity of 1
is very similar to a typical lock. The request
and unlock
functions are a convenient way to interact with such a "lock", in a way mostly compatible with other discrete event and concurrency frameworks.
See Store
for a more channel-like resource.
Think of Resource
and Container
as locks and of Store
as channels. They block only if empty (on taking) or full (on storing).
ConcurrentSim.Store
— TypeStore{T}(env::Environment; capacity::UInt=typemax(UInt))
A store is a resource that can hold a number of items of type T
. It is similar to a Base.Channel
with a finite capacity (put!
blocks after reaching capacity). The put!
and take!
functions are a convenient way to interact with such a "channel" in a way mostly compatible with other discrete event and concurrency frameworks.
See Container
for a more lock-like resource.
Think of Resource
and Container
as locks and of Store
as channels. They block only if empty (on taking) or full (on storing).
Base.islocked
— Methodislocked(::Container)
Returns true
if the store is full, similarly to the meaning of islocked
for Base.ReentrantLock
.
julia> sim = Simulation(); res = Resource(sim, 2); islocked(res)
false
julia> request(res); islocked(res)
false
julia> request(res); islocked(res)
true
Base.islocked
— Methodislocked(::Store)
Returns true
if the store is full, similarly to the meaning of islocked
for Base.ReentrantLock
.
julia> sim = Simulation(); store = Store{Symbol}(sim; capacity=2); islocked(store)
false
julia> put!(store, :message); islocked(store)
false
julia> put!(store, :another_message); islocked(store)
true
Base.isready
— Methodisready(::Container)
Returns true
if the Container is not empty, similarly to the meaning of isready
for Base.Channel
.
julia> sim = Simulation(); res = Resource(sim); isready(res)
false
julia> request(res); isready(res)
true
Base.isready
— Methodisready(::Store)
Returns true
if the store is not empty, similarly to the meaning of isready
for Base.Channel
.
julia> sim = Simulation(); store = Store{Symbol}(sim); isready(store)
false
julia> put!(store, :message); isready(store)
true
Base.put!
— Methodput!(sto::Store, item::T)
Put an item into the store. Returns the put event, blocking if the store is full.
Base.take!
— Functiontake!(::Store)
An alias for get(::Store)
for easier interoperability with the Base.Channel
interface. Blocks if the store is empty.
Base.unlock
— Methodunlock(res::Container)
Unlocks the Container and return the unlock event.
ConcurrentSim.request
— Methodrequest(res::Container)
Locks the Container (or Resources) and return the lock event. If the capacity of the Container is greater than 1, multiple requests can be made before blocking occurs.
ConcurrentSim.tryrequest
— Methodtryrequest(res::Container)
If the Container (or Resource) is not locked, locks it and return the lock event. Returns false
if the Container is locked, similarly to the meaning of trylock
for Base.ReentrantLock
.
If the capacity of the Container is greater than 1, multiple requests can be made before blocking occurs.
julia> sim = Simulation(); res = Resource(sim);
julia> ev = tryrequest(res)
ConcurrentSim.Put 1
julia> typeof(ev)
ConcurrentSim.Put
julia> tryrequest(res)
false