Remove undefined behavior from the startup conditions #132
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I noticed a very non-deterministic behavior where sometimes one or more lifts would be unable to function from the moment the simulation started, and nothing seemed to allow them to recover. This would only happen once in a while and there was no consistency except that it happened immediately at startup and not under any other circumstance.
After some debugging I found that the
DoorModeCmp
for lifts was being initialized without a specific value set for thedoor_state
. Most of the time memory used by programs will be zero-initialized, so most of the time thedoor_state
field was getting set to 0, which coincidentally gives us the correct behavior. But a zero-initialization is not guaranteed, so when that doesn't happen thedoor_state
field will be some arbitrary number, and then the state machine for the lift will just never be functional.This PR simply makes sure that field is set to the correct value at initialization. I haven't seen the bug happen again after this fix.