一句话:通过类型系统与动态优先级调整,防止互斥锁和条件变量使用中的优先级反转,实现响应式并行。
许多并发程序通过给线程分配优先级来提升响应性,但在与互斥锁、条件变量等同步机制结合时,高优先级线程可能被低优先级线程阻塞,产生优先级反转。互斥锁的优先级反转可用优先级继承等动态技术处理,条件变量上的优先级反转则研究不足且动态技术不适用。本文结合静态与动态技术,防止同时使用互斥锁和条件变量时的优先级反转:类型系统保证条件变量的安全使用,而运行时动态调整线程优先级以消除互斥锁中的优先级反转。作者基于并行程序代价模型建立优先级反转模型,证明了类型系统的可靠性,并将其编码进 Rust 和 C++ 类型系统。通过较大规模案例研究,包括将 Memcached 对象服务器移植到 C++ 实现,表明约束并不过于繁重。
Many concurrent programs assign priorities to threads to improve responsiveness. When used in conjunction with synchronization mechanisms such as mutexes and condition variables, however, priorities can lead to priority inversions, in which high-priority threads are delayed by low-priority ones. Priority inversions in the use of mutexes are easily handled using dynamic techniques such as priority inheritance, but priority inversions in the use of condition variables are not well-studied and dynamic techniques are not suitable. In this work, we use a combination of static and dynamic techniques to prevent priority inversion in code that uses mutexes and condition variables. A type system ensures that condition variables are used safely, even while dynamic techniques change thread priorities at runtime to eliminate priority inversions in the use of mutexes. We prove the soundness of our system, using a model of priority inversions based on cost models for parallel programs. To show that the type system is practical to implement, we encode it within the type systems of Rust and C++, and show that the restrictions are not overly burdensome by writing sizeable case studies using these encodings, including porting the Memcached object server to use our C++ implementation.
@article{paperbot1992,
title = {Responsive Parallelism with Synchronization},
author = {Stefan K. Muller and Kyle Singer and Devyn Terra Keeney and Andrew Neth and Kunal Agrawal and I-Ting Angelina Lee and Umut A. Acar},
journal = {Proceedings of the ACM on Programming Languages},
volume = {7},
number = {PLDI},
year = {2023},
doi = {10.1145/3591249}
}