arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2512.08563cs.DC
收藏

轻量线程环境中的基本锁算法

Basic Lock Algorithms in Lightweight Thread Environments

ITMO University(圣彼得堡信息技术、机械与光学大学);Huawei(华为)

Taras Skazhenik, Nikolai Korobenikov, Andrei Churbanov, Anton Malakhov, Vitaly Aksenov

AI总结:

本文研究了轻量线程环境中互斥锁的实现,提出改进的TTAS和MCS锁,并推荐cohort锁以平衡性能与兼容性。

摘要:

传统多线程数据结构是为操作系统线程访问而设计的。然而,为可编程替代方案,即轻量线程(也称为异步调用或协程)访问而设计的实现尚未得到充分研究。轻量线程的主要优势是启动和上下文切换的显著较低开销。然而,这带来了代价:为了实现正确的并行性,上下文切换必须在代码中手动调用;没有这些切换,新的轻量线程将永远不会被执行。本文聚焦于最简单的多线程数据结构:互斥锁(也称为锁)。我们证明,原始为操作系统线程设计的实现无法在新环境中有效使用,因为存在死锁的潜在风险。此外,正确性并非唯一关注点。在某些语言如C++中,有各种轻量线程库,每个都有不同的实现和接口,这需要不同的锁实现。在本工作中,我们提出了一种TTAS和MCS锁的修改版本,用于轻量线程使用,并展示出轻量线程的两种上下文切换机制,即等待和睡眠,是至关重要的。然而,TTAS和MCS的性能可能根据设置显著不同。如果希望有一个适用于任何库的锁,我们建议使用cohort锁,它通过使用多个MCS队列和一个共同的TTAS,在MCS和TTAS之间取得平衡。

英文摘要:

Traditionally, multithreaded data structures have been designed for access by the threads of Operating Systems (OS). However, implementations for access by programmable alternatives known as lightweight threads (also referred to as asynchronous calls or coroutines) have not been thoroughly studied. The main advantage of lightweight threads is their significantly lower overhead during launch and context switching. However, this comes at a cost: to achieve proper parallelism, context switches must be manually invoked in the code; without these switches, new lightweight threads will never be executed. In this paper, we focus on the simplest multithreaded data structure: a mutex (also known as a lock). We demonstrate that original implementations for OS threads cannot be used effectively in this new context due to the potential for deadlocks. Furthermore, correctness is not the only concern. In certain languages, such as C++, there are various lightweight thread libraries, each with different implementations and interfaces, which necessitate distinct lock implementations. In this work, we present a modification of TTAS and MCS locks for the use from lightweight threads and demonstrate that the two context switch mechanisms of lightweight threads, yielding and sleeping, are crucial. However, the performance of TTAS and MCS may differ significantly depending on the settings. If one wants to have a lock that works well for any library, we suggest using the cohort lock, which strikes a balance between MCS and TTAS by utilizing several MCS queues with a common TTAS.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑