Skip to content

Resources

Shared-capacity primitives a process yields on: counting and priority resources, the numeric container, and the message stores. All are re-exported from the top-level llmsim package.

Resources

Resource

Resource(sim, capacity=1)

Bases: BaseResource[Request, Release]

A pool of capacity interchangeable slots requested and released by processes.

Requests beyond capacity queue in FIFO order and are granted as slots free.

Create a resource with capacity slots.

Raises:

Type Description
ValueError

if capacity is not positive.

count property

count

The number of slots currently in use.

request

request()

Request a usage slot.

release

release(request)

Release the slot held by request.

PriorityResource

PriorityResource(sim, capacity=1)

Bases: Resource

A :class:Resource that grants queued requests by ascending priority.

request

request(priority=0, preempt=True)

Request a usage slot at the given priority.

PreemptiveResource

PreemptiveResource(sim, capacity=1)

Bases: PriorityResource

A :class:PriorityResource whose holders can be preempted.

A request that cannot be granted may bump the lowest-priority current holder -- if that holder ranks below the request -- by removing it and interrupting its process with a :class:Preempted cause.

Container

Container

Container(sim, capacity=float('inf'), init=0)

Bases: BaseResource[ContainerPut, ContainerGet]

A shared level of homogeneous matter between 0 and capacity.

Puts block while there is not enough free space; gets block while there is not enough matter. Both wake as the level changes.

Create a container holding init of capacity matter.

Raises:

Type Description
ValueError

if capacity is not positive, init is negative, or init exceeds capacity.

level property

level

The current amount of matter in the container.

put

put(amount)

Request to add amount of matter.

get

get(amount)

Request to draw amount of matter.

Stores

Store

Store(sim, capacity=float('inf'))

Bases: BaseResource[StorePut, StoreGet[T]], Generic[T]

A buffer of up to capacity items, put and retrieved in FIFO order.

Create a store holding up to capacity items.

Raises:

Type Description
ValueError

if capacity is not positive.

put

put(item)

Request to put item into the store.

get

get()

Request to get the next item from the store.

PriorityStore

PriorityStore(sim, capacity=float('inf'))

Bases: Store[T]

A store that retrieves its smallest item first.

All items must be orderable (implement __lt__); wrap unorderable items in :class:PriorityItem.

FilterStore

FilterStore(sim, capacity=float('inf'))

Bases: Store[T]

A store whose gets can be restricted to items matching a predicate.

Because a get may skip non-matching items, gets are not necessarily served in the order they were issued: a later get with a satisfiable filter can be granted ahead of an earlier one still waiting for its item.

get

get(filter=lambda _item: True)

Request the first item matching filter.