
##Note for AbstractQueueSynchronizer
- Synchronizer process two kind of operation:
- acquire
- release
- operation of acquire as:
12345
if(synchronization state does not allow acquire){ enqueue current thread if not already queued; block current thread}dequeue current thread if it was queued;
-
operation of release as:
1234update synchronization state;if(state may permit a blocked thread to acquire){unblock one or more queued threads;} -
Support for these operation require the coordination of these basic components:
- Atomically managing synchronization state;
- Blocking and unblocking thread;
- Maintaing queue;
-
AbstractQueuedSynchronizer maintains synchronization state using only a single (32bit) int.
-
LockSupport.parkoperation issued the problem of Thread.suspend while multipleresumecalled beforesuspendthrough not counted.
Queue
-
There are two candicates to implemtent queue:
- MCS(Mellor-Crummey and Scott).In fact,I don’t know what it is.
- CLH,a low-level locks that is used only in spinlock.
-
The main additional modification needed to use CLH queues for blocking synchronizer is to provide an efficiency way for one node to locate its successor.
- Once it need change,in spinlocks,the node will be notified on next spin by its successor.
- But in blocking queue,the node need to explicitly wake up its successor by
Lock.unpark.
-
To provide an atomically
insertion nodeopertion.Because of the speciality oflocateopertion,the node only need guaranteeentailis atomic.
Usage
-
Concrete subclass need to implement
tryAcquireandtryReleasethrough by inspecting and updating state. -
Shared-mode,
ReentrantReadWriteLock,will wake up multiple thread by cascading singals.




近期评论