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

InputCommon: Fix deadlock in EmulatedController::UpdateReferences(). #11040

Merged

Conversation

AdmiralCurtiss
Copy link
Contributor

@AdmiralCurtiss AdmiralCurtiss commented Sep 7, 2022

There's a deadlock here that can happen if thread A calls UpdateReferences() while thread B holds the DeviceContainer::m_devices_mutex and before releasing it also calls UpdateReferences(). The UpdateReferences() first locks the s_get_state_mutex, then locks the m_devices_mutex (indirectly first via the HasConnectedDevice() call, but also potentially later down the UpdateReferences() chain in eg. ControlExpression::UpdateReferences()). If m_devices_mutex is already locked by another thread that subsequently tries to acquire the s_get_state_mutex -- for example, the HotkeyScheduler thread calling UpdateInput() which in turn triggers a InvokeDevicesChangedCallbacks() which in turn also triggers UpdateReferences() -- they both try to lock the mutex the other thread already holds, deadlocking in the process.

This is the deadlock I mentioned in #11038.

@shuffle2
Copy link
Contributor

shuffle2 commented Sep 7, 2022

Nice, i just got around to hooking up debugger and getting stacks and you fixed it already :)

@lioncash lioncash merged commit 348db11 into dolphin-emu:master Sep 8, 2022
11 checks passed
@AdmiralCurtiss AdmiralCurtiss deleted the update-references-deadlock branch September 8, 2022 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants