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. |
PriorityResource ¶
PriorityResource(sim, capacity=1)
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. |
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. |
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.