|
BoundedBuffer Events WaitFor Reneging
| |
Purpose of the SimPy Laboratory pages
SimPy is not only a mature package for making simulations or teaching the
simulation approach. It also makes a good environment, a "laboratory",
for trying out new simulation constructs. This page therefore addresses experiments
with extending SimPy. Programs, code snippets and just ideas will be presented.
User and developer feedback is sought -- constructs considered useful by the
SimPy community may be introduced in future releases. A word of warning --
code presented here is still experimental and not tested to SimPy's normal
production quality standards.
Experiments
An approach to synchronizing processes which communicate via a buffer of
fixed size which avoids buffer overflow and buffer underflow.
This code addresses how to let a process (or group of processes) wait for
an event which is set by another process. The example's code shows one possible solution,
primarily for tutorial reasons -- SimPy 1.5 provides an event signaling
capability "out of the box".
Certain models which require a process to wait until a general boolean
condition (like "day== Saturday' and resources<= 3") is
satisfied could not be easily/cleanly implemented in SimPy before version 1.5. The
example's code shows one possible solution, primarily for tutorial reasons
-- SimPy 1.5 provides a waitUntil capability "out of the box".
In many real world scenarios, customer processes waiting for a resource
get impatient and leave the wait queue to do something else, e.g. join
another queue. Two recipes for this reneging are shown, one
for timeouts and one in response to a general condition becoming true.
|