fix: 修复 DSysInfo 在 AArch64 架构下的线程安全问题#540
Merged
18202781743 merged 1 commit intolinuxdeepin:masterfrom Feb 5, 2026
Merged
Conversation
在 AArch64 弱内存模型下,DSysInfoPrivate 的多个 ensure* 函数由于缺乏 互斥锁保护,在多线程并发访问时(如应用商店后台服务)会导致以下问题: 1. 引用计数损坏:由于读取到初始化一半的 QString 指针,导致非对齐访问触发 SIGBUS。 2. 堆内存损坏:多个线程同时解析文件并操作 QMap/QByteArray 导致 double free。 3. 状态可见性问题:一个核心修改了初始化标志位,但其他核心看到的成员变量尚未完成写入。 本修改通过在 DSysInfoPrivate 中引入 QMutex,确保了单例初始化过程的原子性 和内存可见性。 Log: 修复 AArch64 架构下 DSysInfo 随机触发 SIGBUS/SIGSEGV 崩溃的问题。 Bug: https://pms.uniontech.com/bug-view-350151.html Change-Id: Ib23b078c3eef5c3ad8aef5a36035ac4839d11bb2
Contributor
deepin pr auto review这段代码主要是在 1. 语法逻辑
2. 代码质量
3. 代码性能
4. 代码安全
改进建议
改进后的代码示例void DSysInfoPrivate::ensureDeepinInfo()
{
// 第一次检查,避免不必要的锁
if (static_cast<int>(deepinType) > 0 && !inTest())
return;
QMutexLocker locker(&mutex);
// 第二次检查,防止在等待锁时其他线程已经更新了数据
if (static_cast<int>(deepinType) > 0 && !inTest())
return;
// 原有逻辑...
}总结这段代码通过引入互斥锁有效地解决了多线程环境下的数据竞争问题,但在性能优化和代码文档化方面还有改进空间。建议采用双重检查锁定模式,并明确锁的用途,以提高代码的并发性能和可维护性。 |
mhduiy
approved these changes
Feb 5, 2026
Contributor
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 18202781743, mhduiy The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
在 AArch64 弱内存模型下,DSysInfoPrivate 的多个 ensure* 函数由于缺乏
互斥锁保护,在多线程并发访问时(如应用商店后台服务)会导致以下问题:
本修改通过在 DSysInfoPrivate 中引入 QMutex,确保了单例初始化过程的原子性
和内存可见性。
Log: 修复 AArch64 架构下 DSysInfo 随机触发 SIGBUS/SIGSEGV 崩溃的问题。
Bug: https://pms.uniontech.com/bug-view-350151.html
Change-Id: Ib23b078c3eef5c3ad8aef5a36035ac4839d11bb2