阻塞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....
lock_mode => DBMS_LOCK.EXCLUSIVE, wait_time => 300); -- 修改 SQL 或 PL/SQL 对象 -- ... -- 释放锁 DBMS_LOCK.RELEASE(lock_id => l_lock_id); EXCEPTION WHEN OTHERS THEN -- 处理异常 DBMS_LOCK....
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 ...
A lock is a tool that enforces restrictions on concurrent access to a data item. There are two main lock modes: 1. **Exclusive (X) mode**: Allows both reading and writing of the data item. A ...
- **Row Exclusive Table Lock (RX)**:也称为Sub-Exclusive Table Lock (SX),通常表示持有该锁的事务正准备更新整个表,但还没有实际开始更新。这种模式允许其他用户读取表中的数据,但不允许修改。 #### 结论 ...
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, ...
在给定的文件"rwlock.cpp"和"rwlock.h"中,我们可以看到一个实现了Windows的slim read/write lock算法的Linux版本。下面将详细讲解读写锁的工作原理、特性以及如何在Linux下实现。 首先,了解读写锁的基本概念: 1...
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 ...
- **Exclusive(独占)**:只有一个线程能执行,如ReentrantLock。 - **Shared(共享)**:多个线程可以同时执行,如Semaphore和CountDownLatch。 AQS还定义了两种等待队列: - **同步等待队列**:当线程尝试获取...
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...