The lock is a building-block synchronization primitive that enables mutually exclusive access to shared data in shared-memory parallel programs. Mutual exclusion is typically achieved by guarding the code that accesses the shared data with a pair of lock() and unlock() operations. Concurrency bugs arise when this ordering of operations is violated. In this paper, we study a particular pattern of misuse where an unlock() is issued without first issuing a lock(), which can happen in code with complex control flow. This misuse is surprisingly common in several important open-source repositories we study. We systematically study what happens due to this misuse in several popular locking algorithms. We study how misuse can be detected and how the locking protocols can be fixed to avoid the unwanted consequences of misuse. Most locks require simple changes to detect and prevent this misuse. We evaluate the performance traits of modified implementations, which show mild performance penalties in most scalable locks.
翻译:锁是一种构建同步原语,用于在共享内存并行程序中实现对共享数据的互斥访问。互斥通常通过使用lock()和unlock()操作对来保护访问共享数据的代码段。当这种操作顺序被违反时,就会出现并发错误。本文研究了一种特定的误用模式,即在未先执行lock()的情况下调用unlock(),这种情况可能出现在具有复杂控制流的代码中。这种误用在我们研究的多个重要开源代码仓库中惊人地普遍。我们系统研究了这种误用发生在若干流行锁算法中的具体表现,分析了误用检测方法以及如何修复锁协议以避免非预期后果。大多数锁只需简单修改即可检测并阻止此类误用。我们评估了修改后实现的性能特征,结果表明大多数可扩展锁仅产生轻微的性能代价。