Skip to content

Preventing patients being "lost" / race condition #202

Description

@thigger

I'm modelling a hospital, and patients must always have at least one ward bed seized (they will briefly have two when changing). If a ward bed is closed (set_capacity) then the patient must not fall into a queue (so queue_size_strict is used). However a patient should be able to queue for a bed once they already have one (for example moving out of the emergency dept into a ward).

The suggestion was to have a queue size of zero, and use a reject trajectory on the seize to increase the queue size and retry the seize.

However, this results in a race condition whereby a second patient can enter the queue in the time between the successful seize and the queue size being decreased again.

The approach I am currently using is to add a flag to control queueing behaviour with the seize (PR #198). This won't solve other possible races - eg if a ward closure causes a patient to drop into a queue briefly, but in that case when the queue is decreased they will go via handle_unfinished in the same way that they would have if the queue size had been decremented already.

An alternative may be creative use of handle_unfinished, but willqueue seems to be working well for me at present - and I'm happy to tweak as required.

I've knocked up an example - I'm sure it could be made smaller but at least it's reproducible.

race condition test - Copy.R.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions