Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The event queue in TOSSIM is unstable (in terms of sorting order) #419

Open
MBradbury opened this issue Oct 23, 2017 · 0 comments
Open

The event queue in TOSSIM is unstable (in terms of sorting order) #419

MBradbury opened this issue Oct 23, 2017 · 0 comments

Comments

@MBradbury
Copy link
Contributor

Currently running a simulation with a seed produces a deterministic output. Running the same code but inserting simulation events that do nothing will produce a different deterministic output. I was expecting the output from the two simulations to be the same.

It turns out that because the queue is implemented in terms of a heap it is not stable (in terms of sorting order). For example, if events A, B and C are scheduled to run at time t they may be executed in the order BCA. If an empty event E is also scheduled at t then that order may change to CAEB, essentially CAB.

This was unexpected behaviour, as I didn't expect asking for an event that does nothing to be called to change the output of the simulation.

The solution to this is to add a counter that records the number of events scheduled and assign each event a unique counter. The event counter would be used in the heap comparison to ensure events added first would be called first.

However, I'm not sure if this is a bug that needs fixing, or if it is just something worth documenting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant