ConcurrentSim.ConcurrentSimModule

Main module for ConcurrentSim.jl – a discrete event process oriented simulation framework for Julia.

ConcurrentSim.ContainerType
Container{N<:Real, T<:Number}(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, Int}.

Resource() with default capacity of 1 is very similar to a typical lock. The lock 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. The request and release aliases are also available for these two functions.

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.QueueStoreType
QueueStore{N, T<:Number}

A store in which items are stored in a FIFO order.

julia> sim = Simulation()
       store = Store{Symbol}(sim)
       queue = QueueStore{Symbol}(sim)
       items = [:a,:b,:a,:c];

julia> [put!(store, item) for item in items];

julia> [value(take!(store)) for _ in 1:length(items)]
4-element Vector{Symbol}:
 :a
 :a
 :b
 :c

julia> [put!(queue, item) for item in items];

julia> [value(take!(queue)) for _ in 1:length(items)]
4-element Vector{Symbol}:
 :a
 :b
 :a
 :c

See also: StackStore, Store

ConcurrentSim.StackStoreType
StackStore{N, T<:Number}

A store in which items are stored in a FILO order.

julia> sim = Simulation()
       store = Store{Symbol}(sim)
       stack = StackStore{Symbol}(sim)
       items = [:a,:b,:a,:c];

julia> [put!(store, item) for item in items];

julia> [value(take!(store)) for _ in 1:length(items)]
4-element Vector{Symbol}:
 :a
 :a
 :b
 :c

julia> [put!(stack, item) for item in items];

julia> [value(take!(stack)) for _ in 1:length(items)]
4-element Vector{Symbol}:
 :c
 :a
 :b
 :a

See also: QueueStore, Store

ConcurrentSim.StoreType
Store{N, T<:Number}(env::Environment; capacity::UInt=typemax(UInt))

A store is a resource that can hold a number of items of type N. 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/stacks. They block only if empty (on taking) or full (on storing).

Store does not guarantee any order of items. See StackStore and QueueStore for ordered variants.

julia> sim = Simulation(); store = Store{Int}(sim);

julia> put!(store, 1); run(sim, 1); put!(store, 2);

julia> value(take!(store))
2

julia> value(take!(store))
1
Base.islockedMethod
islocked(::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.islockedMethod
islocked(::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.isreadyMethod
isready(::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.isreadyMethod
isready(::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.lockMethod
lock(res::Resource)

Locks the Resource and return the lock event. If the capacity of the Container is greater than 1, multiple requests can be made before blocking occurs.

Base.put!Method
put!(sto::Store, item::T)

Put an item into the store. Returns the put event, blocking if the store is full.

Base.take!Function
take!(::Store)

An alias for get(::Store) for easier interoperability with the Base.Channel interface. Blocks if the store is empty.

Base.trylockMethod
trylock(res::Resource)

If the 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
Base.unlockMethod
unlock(res::Resource)

Unlocks the Resource and return the unlock event.