arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2111.12682cs.PLcs.DS
收藏

CQS:一个支持公平且可中止同步的形式化验证框架

CQS: A Formally-Verified Framework for Fair and Abortable Synchronization

Nikita Koval, Dmitry Khalanskiy, Dan Alistarh

AI总结:

本文提出了CQS框架,支持高效实现公平且可中止的同步原语,并在Coq的Iris框架中提供模块化的形式化证明,其在JVM上的实际性能显著优于Java的AbstractQueuedSynchronizer。

摘要:

编写既正确又高效的并发代码是出了名的困难。因此,程序员通常倾向于使用同步抽象,这使得代码更简单且更容易推理。尽管关于该主题已有大量研究,但现代编程语言中同步抽象所提供的丰富语义——具体而言,即同步请求的公平 FIFO 排序以及对可中止操作的支持——与能够正确且高效地实现这些语义的框架之间,仍然存在差距。鉴于异步编程构造(如协程)的日益普及,支持此类语义变得至关重要,因为协程会频繁中止,并且与原生线程相比,其挂起和恢复的成本更低。本文引入了一个名为 CancellableQueueSynchronizer (CQS) 的新框架,该框架支持对各种公平且可中止的同步原语进行简单而高效的实现:互斥锁、信号量、屏障、倒计时锁存器和阻塞池。我们的主要贡献在于算法层面,因为在这种通用性级别上高效地实现公平性和可中止性并非易事。重要的是,我们所有的算法,包括 CQS 框架以及构建在其之上的原语,都在 Coq 的 Iris 框架中附带了针对其许多属性的形式化证明。这些证明是模块化的,因此很容易证明在 CQS 之上实现的新原语的正确性。从实际角度来看,在 JVM 上针对原生线程的 CQS 实现显著改进了 Java 的 AbstractQueuedSynchronizer,这是唯一提供类似语义的实用抽象。总而言之,CancellableQueueSynchronizer 是第一个将表达能力、形式化保证和良好的实际性能结合起来的框架。

英文摘要:

Writing concurrent code that is both correct and efficient is notoriously difficult. Thus, programmers often prefer to use synchronization abstractions, which render code simpler and easier to reason about. Despite a wealth of work on this topic, there is still a gap between the rich semantics provided by synchronization abstractions in modern programming languages -- specifically, \emph{fair} FIFO ordering of synchronization requests and support for \emph{abortable} operations -- and frameworks for implementing it correctly and efficiently. Supporting such semantics is critical given the rising popularity of constructs for asynchronous programming, such as coroutines, which abort frequently and are cheaper to suspend and resume compared to native threads. This paper introduces a new framework called \texttt{CancellableQueueSynchronizer} (CQS), which enables simple yet efficient implementations of a wide range of fair and abortable synchronization primitives: mutexes, semaphores, barriers, count-down latches, and blocking pools. Our main contribution is algorithmic, as implementing both fairness and abortability efficiently at this level of generality is non-trivial. Importantly, all our algorithms, including the CQS framework and the primitives built on top of it, come with \emph{formal proofs} in the Iris framework for Coq for many of their properties. These proofs are modular, so it is easy to show correctness for new primitives implemented on top of CQS. From a practical perspective, implementation of CQS for native threads on the JVM significantly improves Java's \texttt{AbstractQueuedSynchronizer}, the only practical abstraction offering similar semantics. In sum, \texttt{CancellableQueueSynchronizer} is the first framework to combine expressiveness with formal guarantees and solid practical performance.

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

↑