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

Introduce a watchdog thread to handle termination gracefully #6

Merged
merged 1 commit into from
May 4, 2023

Conversation

abbysmal
Copy link
Collaborator

This addresses issue #2 as well.

The source of the segfault was that, on ctrl-c, we would often find ourselves in situations where we can close the Midi.device twice. (once in the signal handler, once at the termination of the main thread, that is also calling Midi.shutdown.)

Another source of segfault was having the sequencer thread in stat_engine write to a device that was closed by said signal handler.

I also noticed that the stat_engine would not check the child_alive function to see if the instrumented program was still running or not, leading to cardio-crumble running indefinitely trying to poll events that would never show up.

I decided to implement a solution to all of these problems by adding a watchdog thread to be run alongside any threads the engine is using.

The idea being it is that it would introduce a Watchdog.terminate atomic variable, that each thread should check from time to time. If Watchdog.terminate is true, then said threads should be exiting gracefully.

The watchdog domain itself is just checking that child_alive is false (meaning the instrumented program has stopped).

If it detects it is the case, it will then set terminate to true, and exit.

This may be an overkill solution, but I think it works quite nicely, let me know if you have any nicer idea. :-)

Copy link
Owner

@pitag-ha pitag-ha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeaaaaaaaaaaaaaaaaah! :)

@pitag-ha pitag-ha merged commit a899ec8 into main May 4, 2023
@pitag-ha pitag-ha deleted the watchdog branch May 4, 2023 17:39
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