24U 161 84 108 119
Table 3 Saturated Per-Lock Overhead in Nanoseconds
Machine Builtin Mutex Reentrant Fair
1P 521 46 67 8327
2P 930 108 132 14967
2A 748 79 84 33910
4P 1146 188 247 15328
1U 879 153 177 41394
4U 2590 347 368 30004
8U 1274 157 174 31084
24U 1983 160 182 32291
Table 3 also illustrates that even with low internal overhead, context switching time completely determines performance for Fair locks。 The listed times are roughly proportional to those for blocking and unblocking threads on the various platforms。
Additionally, a follow-up experiment (using machine 4P only) shows that with the very briefly held locks used here, fairness settings had only a small impact on overall variance。 Differences in termination times of threads were recorded as a coarse-grained measure of variability。 Times on machine 4P had standard deviation of 0。7% of mean for Fair, and 6。0% for Reentrant。 As a contrast, to simulate long-held locks, a version of the test was run in which each thread computed 16K random numbers while holding each lock。 Here, total run times were nearly identical (9。79s for Fair, 9。72s for Reentrant)。 Fair mode variability remained small, with standard deviation of 0。1% of mean, while Reentrant rose to 29。5% of mean。
5。2Throughput
Usage of most synchronizers will range between the extremes of no contention and saturation。 This can be experimentally examined along two dimensions, by altering the contention probability of a fixed set of threads, and/or by adding more threads to a set with a fixed contention probability。 To illustrate these effects, tests were run with different contention probablilities and numbers of threads, all using Reentrant locks。 The accompanying figures use a slowdown metric:摘要
在J2SE 1。5的java。util。concurrent包(下称j。u。c包)中,大部分的同步器(例如锁,屏障等等)都是基于AbstractQueuedSynchronizer(下称AQS类)这个简单的框架来构建的。这个框架为同步状态的原子性管理、线程的阻塞和解除阻塞以及排队提供了一种通用机制。这篇论文主要描述了这个框架基本原理、设计、实现、用法以及性能。
1。 背景介绍
通过JCP的JSR166规范,Java的1。5版本引入了j。u。c包,这个包提供了一系列支持中等程度并发的类。这些组件是一系列的同步器(抽象数据类型(ADT))。这些同步器主要维护着以下几个功能:内部同步状态的管理(例如:表示一个锁的状态是获取还是释放),同步状态的更新和检查操作,且至少有一个方法会导致调用线程在同步状态被获取时阻塞,以及在其他线程改变这个同步状态时解除线程的阻塞。上述的这些的实际例子包括:互斥排它锁的不同形式、读写锁、信号量、屏障、Future、事件指示器以及传送队列等。