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

fix: address mutex deadlock in state machine #627

Merged
merged 4 commits into from
Apr 15, 2024
Merged

Conversation

james-ctc
Copy link
Contributor

Describe your changes

There was a deadlock in the IEC state machine when the C1 timer expires whilst the state machine is running and attempting to stop the timer.

The timer raises an event (hence blocks on the mutex) Stopping the timer waits for the thread to finish. Since the state machine is holding the mutex the thread never finishes ...

fix: improvement to EventQueue

Wait on the condition variable now checks the queue size to avoid spurious wakeups.
https://en.cppreference.com/w/cpp/thread/condition_variable

Issue ticket number and link

Checklist before requesting a review

  • I have performed a self-review of my code
  • I have made corresponding changes to the documentation
  • I read the contribution documentation and made sure that my changes meet its requirements

There was a deadlock in the IEC state machine when the C1 timer
expires whilst the state machine is running and attempting to
stop the timer.

The timer riases an event (hence blocks on the mutex)
Stopping the timer waits for the thread to finish.
Since the state machine is holding the mutex the thread
never finishes ...

fix: improvement to EventQueue

Wait on the condition variable now checks the queue size to
avoid spurious wakeups.
https://en.cppreference.com/w/cpp/thread/condition_variable

Signed-off-by: James Chapman <[email protected]>
Signed-off-by: James Chapman <[email protected]>
The IEC state machine uses threads to decouple events from the
state machine, hence events don't always arrive in the expected
order which causes some tests to occasionally fail.

Signed-off-by: James Chapman <[email protected]>
@james-ctc james-ctc merged commit 7480d34 into main Apr 15, 2024
4 of 5 checks passed
@james-ctc james-ctc deleted the fix/mutex-deadlock branch April 15, 2024 07:58
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

Successfully merging this pull request may close these issues.

2 participants