Skip to content

Preemptive

Preemptive shared resource.

Preempted dataclass

Interrupt cause delivered when a process is evicted from a PreemptiveResource.

Attributes:

Name Type Description
by Process

the process that caused the preemption.

usage_since float

simulation time when the preempted process acquired the resource.

PreemptiveResource

Shared resource where higher-priority processes can preempt lower-priority users.

Priority is an integer; lower values are served first (0 is highest priority). When a new acquire request has better priority than the worst current user and preempt=True, that user is interrupted with a Preempted cause and removed from the resource. The preempted process is responsible for catching the Interrupt, tracking remaining work, and re-acquiring.

Do not call release() when handling a Preempted interrupt: the preempted process has already been removed from the user list by the preemptor.

count property

Current number of active users.

acquire(priority=0, preempt=True) async

Acquire one unit of the resource.

Must be called from within a Process.run() coroutine; the calling process is identified via env._active_process.

Parameters:

Name Type Description Default
priority int

lower value = higher priority (0 is best).

0
preempt bool

if True, may interrupt the lowest-priority current user when the resource is full and that user has lower priority than this request.

True

release()

Release one unit of the resource.

The calling process is identified via env._active_process. Do not call this when handling a Preempted interrupt: the preempted process has already been removed from the user list by the preemptor.

Raises:

Type Description
RuntimeError

if the calling process is not a current user.