WinMM: avoid deadlock - #372
Conversation
|
Heads up — we ran into this same deadlock while fixing #376 and came up with the same approach, before spotting your PR. Sorry for the duplicate effort. Our version is in #380, but it is bundled with a larger input teardown rewrite, so yours is the smaller and more obviously reviewable fix for the deadlock on its own. Happy to rebase ours on top if this one lands first. For what it is worth, we reproduced the crash on real hardware here: |
|
@jkeller51 I'd like to merge this so you get credit and then rebase #380 on top of it, but your PR is failing the MinGW CI check. Would you mind updating it? The CI failure is a one-line fix. Both MinGW jobs fail while Linux, JACK and macOS pass, and the cause is that Adding the include inside the WinMM block, near the other Windows includes, should be enough. Pushing any commit to this branch will also re-trigger the checks, which is the simplest way to get a fresh run. |
|
Okay, I've fixed the issue. |
I was constantly experiencing a deadlock in my application. It seems when calling
midiInReset(), Windows will try to finish processing any remaining input MIDI throughmidiInputCallback(). InclosePort(), the mutex is acquired, thenmidiInReset()is called. If there is any remaining sysex to process,midiInputCallback()will attempt to acquire the mutex from the windows audio thread, leading to a deadlock.This PR attempts to avert the deadlock by setting a closing flag from
closePort(), which will bypass the sysex processing (and mutex acquisition) inmidiInputCallback().