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, fair FIFO ordering of synchronization requests and support for abortable operations--and frameworks for implementing such semantics correctly and efficiently. Supporting such semantics is critical given the rising popularity of constructs for asynchronous programming, such as coroutines, which abort frequently, and should be cheaper to suspend and resume compared to native threads. We introduce a new framework called the CancellableQueueSynchronizer (CQS), which enables efficient fair and abortable implementations of fundamental synchronization primitives such as mutexes, semaphores, barriers, count-down-latches, and blocking pools. Our first contribution is algorithmic, as implementing both fairness and abortability efficiently at this level of generality is non-trivial. Importantly, all our algorithms come with formal proofs in the Iris framework for Coq. These proofs are modular, so it is easy to prove correctness for new primitives implemented on top of CQS. To validate practical impact, we integrated CQS into the Kotlin Coroutines library. Compared against Java's AbstractQueuedSynchronizer, the only practical abstraction to provide similar semantics, CQS shows significant improvements across all benchmarks, of up to two orders of magnitude. In sum, CQS is the first framework to combine expressiveness with formal guarantees and strong practical performance, and should be extensible to other languages and other families of synchronization primitives.
翻译:以正确和高效的方式同时写入代码,这非常困难:因此,程序员往往倾向于使用同步抽象,这会使代码简单易懂。尽管在这一专题上做了大量工作,但现代编程语言、公平的FIFO命令同步请求和支持可中止操作框架,正确和高效地实施这些语义,支持这些语义至关重要。鉴于对非同步编程的构建越来越受欢迎,例如经常中断且比本地线条更便宜地暂停和恢复的正轨。尽管在这一专题上做了大量工作,但是在现代编程语言中同步抽象的抽象抽象游戏(CQS)提供的丰富语义之间仍然存在着差距,这种框架能够有效、公平和可中止地执行同步请求和支持可中止的操作操作,以及正确和高效地实施此类语义学。我们的第一个贡献是算法性,因为在这个一般化水平上,既执行公平性又易变现性基准, Q、我们所有的直基语系直系直系直系直系直系直系直系直系直系直系直系直系直系直系直系直系直系直系直系直系直系直系直系直系直系直系直系直系直系Q。