From 62b07487dc76b5d94d118e7926d216a2cbb8bb5d Mon Sep 17 00:00:00 2001 From: krasjet Date: Wed, 14 Oct 2020 17:40:56 +0000 Subject: [PATCH] fix a deadlock issue in midi_dump The main loop might be blocked by `data_ready` when JACK server dies while the program is running. To reproduce the problem: 1. Start JACK server 2. Run `jack_midi_dump` 3. Stop JACK server 4. Press Ctrl-C in `jack_midi_dump` to send SIGINT. 5. Observe that the program doesn't stop and stuck in the main loop. This patch forces the `data_ready` to be signaled in the signal handler to prevent indefinite waiting. --- tools/midi_dump.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/midi_dump.c b/tools/midi_dump.c index 7a7ec2b3..ef9148b3 100644 --- a/tools/midi_dump.c +++ b/tools/midi_dump.c @@ -112,6 +112,11 @@ process (jack_nframes_t frames, void* arg) static void wearedone(int sig) { fprintf(stderr, "Shutting down\n"); keeprunning = 0; + /* main loop might be blocked by data_ready when jack server dies. */ + if (pthread_mutex_trylock (&msg_thread_lock) == 0) { + pthread_cond_signal (&data_ready); + pthread_mutex_unlock (&msg_thread_lock); + } } static void usage (int status) {