A Formally-Verified Framework for Fair Synchronization in Kotlin Coroutines

11/22/2021
by   Nikita Koval, et al.
0

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.

READ FULL TEXT
research
03/27/2018

Safe Non-blocking Synchronization in Ada 202x

The mutual-exclusion property of locks stands in the way to scalability ...
research
08/31/2020

Correctly Implementing Synchronous Message Passing in the Pi-Calculus By Concurrent Haskell's MVars

Comparison of concurrent programming languages and correctness of progra...
research
03/01/2022

Synthesizing Fine-Grained Synchronization Protocols for Implicit Monitors (Extended Version)

A monitor is a widely-used concurrent programming abstraction that encap...
research
10/20/2011

Efficient Synchronization Primitives for GPUs

In this paper, we revisit the design of synchronization primitives---spe...
research
09/12/2011

Light-weight Locks

In this paper, we propose a new approach to building synchronization pri...
research
11/09/2022

Fast and Scalable Channels in Kotlin Coroutines

Asynchronous programming has gained significant popularity over the last...
research
04/22/2018

Towards formal models and languages for verifiable Multi-Robot Systems

Incorrect operations of a Multi-Robot System (MRS) may not only lead to ...

Please sign up or login with your details

Forgot password? Click here to reset