API

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.DelayQueueType
DelayQueue{T}

A queue in which items are stored in a FIFO order, but are only available after a delay.

julia> sim = Simulation()
       queue = DelayQueue{Symbol}(sim, 10)
       @resumable function producer(env, queue)
           for item in [:a,:b,:a,:c]
               @info "putting $item at time $(now(env))"
               put!(queue, item)
               @yield timeout(env, 2)
           end
       end
       @resumable function consumer(env, queue)
           @yield timeout(env, 5)
           while true
               t = @yield take!(queue)
               @info "taking $(t) at time $(now(env))"
           end
       end
       @process producer(sim, queue)
       @process consumer(sim, queue)
       run(sim, 30)
[ Info: putting a at time 0.0
[ Info: putting b at time 2.0
[ Info: putting a at time 4.0
[ Info: putting c at time 6.0
[ Info: taking a at time 10.0
[ Info: taking b at time 12.0
[ Info: taking a at time 14.0
[ Info: taking c at time 16.0
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.ResourceType

An alias for Container{Int, Int}, one of the most frequently used types of synchronization primitive.

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.put!Method
put!(sto::Store, item::T)

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

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

Unlocks the Resource and return the unlock event.

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

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