阻塞lock的基本流程
if(cas(0,acquire))
setExclusiveOwnerThread
else if(current==getExclusiveOnwerThread) {
setState(c+acquires)
}
addWaiter
park
........................
for(;;) {
p = node.predecessorif(p==head&&tryAcquire(arg)){
setHead(node)return
}park
}
阻塞release的基本流程
if(current!=getExclusiveOnwerThread){
IllegalMonitorStateException
}
if(c == 0){
setExclusive(null)
free = true
}
setState(c)
return free
unparkSuccessor(LockSupport.unpark(thread))
非阻塞lock的基本流程
if(cas(0,acquire))
setExclusiveOwnerThread true
else if(current==getExclusiveOwnerThread)
setState(c+acquire) true
false
非阻塞的release的基本流程
与阻塞的release流程相同
阻塞共享lock的基本流程
tryAcquireShared(acquires){
for(;;) {
remaining = state-acquires
if(remaining<0 || CAS(state,remaining))
return remaining
}
}
if(tryAcquireShared(arg)<0){
node = addWaiter(Node.SHARED)
for(;;) {
p = node.predecessorpropagate = tryAcquireShared(arg)if(p==head&&propagate>=0){
setHead(node)if(propagate>0||next==null||next.isShared())//如果还有剩余,继续唤醒接下来一个节点doReleaseShared()return
}park
}
}
阻塞共享release的基本流程
tryReleaseShared(acquires){
for(;;){if(cas(state,state+acquires))return true}
}
if(tryReleaseShared(acquires)) {
unparkSuccessor(h)
}
共享lock的基本模式
覆盖tryAcquireShared方法
for(;;) { if(state-acquire<0) { false } if(cas(state,state-acquires)) { true } }
共享lock的release的基本模式
覆盖tryReleaseShared方法
for(;;) { if(cas(state,state+acquires)) { true } }排它lock的基本模式
覆盖tryAcquire方法
if(state==0) { if(cas(state, state+acquire)) { setExclusiveOwnerThread(current) return true } } else if(current==getExclusiveOwnerThread) { if(cas(state, state+acquire)) { return true } } return flase排它lock的release基本模式
覆盖tryRelease方法
if(current != getExclusiveThread) { throw new IllegalMonitorStateException() } nextc = state-release if(nextc == 0) { setState(nextc) setExclusiveOwnerThread(current) return true } else { setState(nextc) return false }
相关推荐
An intent lock indicates that SQL Server wants to acquire a shared (S) lock or exclusive (X) lock on some of the resources lower down in the hierarchy. For example, a shared intent lock placed at the ...
An algorithm is merely a set of rules, and anyone with the ability to envision how different components of a business can interact with other components already has the ability to work in algorithms....
Lewis will show you how to build predictive analytic models in less time than you ever imagined possible! Even if you’re a busy professional or a student with little time. By spending as little as ...
this book shows you how to integrate these various elements with key design concepts and principles in order to develop a highly usable interface for the touch screen. You'll learn to use existing ...
Learn to design and build a fully-featured application using the newest cutting-edge framework from Facebook Leverage your JavaScript skills to become a native app developer Develop custom UI ...
Chapter 4 explains how to create a simple weapon management system. You will create weapons (e.g., a gun and a grenade launcher), manage the collection of ammunition, and also implement a user ...
在linux下按照windows的slim read/write lock算法实现的读写锁源码。
It then shows you how to master the asynchronous control flow patterns, and the stream component and it culminates into a detailed list of Node.js implementations of the most common design patterns, ...
Covers a wide range of topics and envisages machine learning as an exclusive way to solve a wide range of biological problems from brain computer interface to no human doctor, from environmental data ...
Starting with an introduction to Ouya, you will learn how to set up an environment and render game levels on Ouya. You will learn how to change levels and how to save the current level. You will then ...
any DSP settings to quickly build up a design, save it as a configuration file, and use it as a template for other systems. MIDI iDR-8 is equipped with MIDI in/out/thru and custom MIDI commands can be...
This book will help you discover all the Rust features that can be used to build software in a functional way. We begin with a brief comparison of the functional and object-oriented approach to ...
You will learn how to build web applications and APIs in Node, discover packages in the Node.js ecosystem, test and deploy your Node.js code, and more. Finally, you will discover how to integrate ...
If you build a clustered index without specifying the unique keyword, SQL Server forces uniqueness by adding a uniqueifier to the rows when necessary. This uniqueifier is a 4-byte value added as an ...
To build and report mutually exclusive machine states you have to be able to distinguish between different states of your manufacturing resources. For machines equipped with FOCAS-enabled Fanuc ...
Uses an EasyNSE exclusive menu editor to build the menu instead of the built in menu editor and TMenuItem. Why you ask? TMenuItem was not designed with a shell extension in mind. Delphi menu items are...
You'll learn how to quickly build such apps with step-by-step tutorials and how to avoid many pitfalls in the process with lots of hard-earned troubleshooting tips. What you will learn Classify ...
Send any kind of midi event out(except system exclusive) through any available midi port
Big Data teaches you to build big data systems using an architecture designed specifically to capture and analyze web-scale data. This book presents the Lambda Architecture, a scalable, easy-to-...