A second set of modifications is to use the status field kept  in each node for purposes of controlling blocking, not spinning。 In the synchronizer framework, a queued thread can only  return from an acquire operation if it passes the tryAcquire method defined in a concrete subclass; a single "released" bit does not suffice。 But control is still needed to ensure that an active  thread is only allowed to invoke tryAcquire when it is at the head of the queue; in which case it may fail to  acquire,  and (re)block。 This does not require a per-node status flag because permission can be determined by checking that the  current  node's predecessor is the head。 And unlike the case of spinlocks,  there is not enough memory contention reading head to warrant replication。 However, cancellation status must still be present in the status field。

The queue node status field is also used to avoid needless calls to park and unpark。 While these methods are relatively fast as blocking primitives go, they encounter avoidable overhead in the boundary crossing between Java and the JVM runtime and/or OS。 Before invoking park, a thread sets a "signal me" bit, and then rechecks synchronization and node status once more before invoking park。 A releasing thread clears status。 This saves threads from needlessly attempting to block often enough to be worthwhile, especially for lock classes in which lost time waiting for the next eligible thread to acquire a lock accentuates other contention effects。 This also avoids requiring a releasing thread to determine its successor unless the successor has set the signal bit, which  in turn  eliminates  those  cases where  it must  traverse

multiple nodes to cope with an apparently null next field unless signalling occurs in conjunction with cancellation。

Perhaps the main difference between the variant of CLH locks used in the synchronizer framework and those employed in other languages is that garbage collection is relied on for managing storage reclamation of nodes, which avoids complexity and overhead。 However, reliance on GC does still entail nulling  of link fields when they are sure to never to be needed。 This can normally be done when dequeuing。 Otherwise, unused nodes would still be reachable, causing them to be uncollectable。

Some further minor tunings, including lazy initialization of the initial dummy node required by CLH queues upon  first contention, are described in the source code documentation in the J2SE1。5 release。

Omitting such details, the general form of the resulting implementation of the basic acquire operation (exclusive, noninterruptible, untimed case only) is:

if (!tryAcquire(arg)) {

node = create and enqueue new node; pred = node's effective predecessor;

while (pred is not head node ||  !tryAcquire(arg)) { if (pred's signal bit is set)

park(); else

compareAndSet pred's signal bit to true; pred = node's effective predecessor;

}

head = node;

The ConditionObject class enables conditions to be efficiently integrated with other  synchronization  operations, again by fixing some design decisions。 This class supports only Java-style monitor access rules in which condition operations are legal only when the lock owning the condition is held by the current thread (See [4] for discussion of alternatives)。 Thus, a ConditionObject attached to a ReentrantLock acts in the same way as do built-in monitors (via Object。wait etc), differing only in method names, extra functionality, and the fact that users can declare multiple conditions per lock。

A ConditionObject uses the same internal queue nodes as synchronizers, but maintains them on a separate condition queue。 The signal operation is implemented as a queue transfer from the condition queue to the lock queue, without necessarily waking up the signalled thread before it has re-acquired its lock。

上一篇:基于约束的纸箱折叠仿真英文文献和中文翻译
下一篇:概率风能模型的发电系统可靠性英文文献和中文翻译

永磁同步电动机的矢量控...

JSP应用框架英文文献中文翻译

SSH框架实现的试题库管理...

塑料注射成型工艺参数优...

冷弯钢门户框架的设计方...

耦合侧向扭转频率的不对...

斜屋顶钢框架结构的弹性...

网络语言“XX体”研究

张洁小说《无字》中的女性意识

麦秸秆还田和沼液灌溉对...

LiMn1-xFexPO4正极材料合成及充放电性能研究

我国风险投资的发展现状问题及对策分析

老年2型糖尿病患者运动疗...

新課改下小學语文洧效阅...

ASP.net+sqlserver企业设备管理系统设计与开发

互联网教育”变革路径研究进展【7972字】

安康汉江网讯