-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Remove note from m_playingNotes before deleting m_pluginData #2422
Conversation
Much cleaner, thanks! FYI - If you modify the PR description to contain "fixes #2401" or "closes #2401", the associated bug report will be closed as soon as this PR is merged. Also, as I'm sure you can observe, the PR title is getting cut off because if it is too long, this is something to consider for future commits or PRs to avoid the |
Done! |
👍 FYI - "fixes" will need to go in the description, not the title for auto-close to work. |
Done (Take 2) |
e8a16d9
to
44e2b9f
Compare
@michaelgregorius @Wallacoloo any thoughts on merging? 👓 |
if( m_playingNotes.indexOf( _n ) >= 0 ) | ||
{ | ||
m_playingNotesMutex.lock(); | ||
m_playingNotes.remove( m_playingNotes.indexOf( _n ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's the possibility that m_playingNotes.indexOf( _n ) >= 0
evaluates to true, then another thread removes _n
, and then we obtain a lock and attempt to call m_playingNotes.remove( m_playingNotes.indexOf( _n ) )
, which would be an error.
The simple solution is to move the locking and unlocking to just outside of the if statement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although, maybe that's not a race condition that you're trying to protect against (as the other note removals don't have these checks). Though you still should lock m_playingNotes
before calling indexOf
in case another thread causes the vector to be resized before indexOf
returns. So in either case, the locking should be moved to outside the conditional.
@tresf I left my feedback. The code inside these lock statements doesn't have the opportunity to hang or call another function that will attempt to obtain other locks, so it looks to be safe and deadlock-free. |
@tresf If I understand correctly this patch is rather a band-aid than fixing the "real" cause of the problem but I think it is still better than having nothing. I investigated the problem together with @midi-pascal in #2401 but unfortunately it is hard to find the root cause (as is most of the times with threading related problems). So with regards to the goal of having a version 1.2 I'd say we should merge this as it provides a solution to the problem. There is always room for improvement later. @midi-pascal Thanks for your endurance in investigating this problem! 😃 |
e5d116c
to
56bbeed
Compare
@Wallacoloo I did what you suggested. |
@michaelgregorius Thanks! This one was tough to find, even if I did not find its root! |
@midi-pascal, try rebase again with HEAD~2. If you click on the |
@tresf I already tried this but I get: This is a combination of 2 commits. Move m_playingNotesMutex.lock() and m_playingNotesMutex.unlock() outside of if( m_playingNotes.indexOf( _n ) >= 0 ) Conflicts: |
ea6553e
to
974d670
Compare
…f2Instrument::deleteNotePluginData() Move m_playingNotesMutex.lock() and m_playingNotesMutex.unlock() outside of if( m_playingNotes.indexOf( _n ) >= 0 ) Conflicts: plugins/sf2_player/sf2_player.cpp Remove note from m_playingNotes before deleting its m_pluginData in sf2Instrument::deleteNotePluginData() Move m_playingNotesMutex.lock() and m_playingNotesMutex.unlock() outside of if( m_playingNotes.indexOf( _n ) >= 0 )
974d670
to
2470df4
Compare
@tresf I think I got it. |
Great. Consensus says 👍, merging. |
Remove note from m_playingNotes before deleting m_pluginData
😄 |
fixes #2401: Random crash in sf2_player