[all-commits] [llvm/llvm-project] b76fd1: [lldb] Avoid deadlock by unlocking before invoking...
Jonas Devlieghere via All-commits
all-commits at lists.llvm.org
Wed Mar 27 16:37:22 PDT 2024
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: b76fd1eddbafaa02a533245d574048c5ad9e38fa
https://github.com/llvm/llvm-project/commit/b76fd1eddbafaa02a533245d574048c5ad9e38fa
Author: Jonas Devlieghere <jonas at devlieghere.com>
Date: 2024-03-27 (Wed, 27 Mar 2024)
Changed paths:
M lldb/source/Host/common/Alarm.cpp
Log Message:
-----------
[lldb] Avoid deadlock by unlocking before invoking callbacks (#86888)
Avoid deadlocks in the Alarm class by releasing the lock before invoking
callbacks. This deadlock manifested itself in the ProgressManager:
1. On the main thread, the ProgressManager acquires its lock in
ProgressManager::Decrement and calls Alarm::Create.
2. On the main thread, the Alarm acquires its lock in Alarm::Create.
3. On the alarm thread, the Alarm acquires its lock after waiting on the
condition variable and calls ProgressManager::Expire.
4. On the alarm thread, the ProgressManager acquires its lock in
ProgressManager::Expire.
Note how the two threads are acquiring the locks in different orders.
Deadlocks can be avoided by always acquiring locks in the same order,
but since the two mutexes here are private implementation details,
belong to different classes, that's not straightforward. Luckily, we
don't need to have the Alarm mutex locked when invoking the callbacks.
That exactly how this patch solves the issue.
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list