Hopefully fixes dead lock

This commit is contained in:
Sotr
2018-08-10 22:01:24 +08:00
parent a64ee6fa0d
commit 5005a19195
2 changed files with 2 additions and 6 deletions

View File

@@ -8,14 +8,10 @@ public class ReentrantSpinningLock {
public void lock() {
long currentThreadId = Thread.currentThread().getId();
attemptLock.getAndSet(true); // In case acquire one lock concurrently
if (heldThreadId != 0 && heldThreadId != currentThreadId) {
attemptLock.set(false);
while (heldThreadId != 0) ; // The current thread is spinning here
attemptLock.getAndSet(true);
}
attemptLock.getAndSet(true); // In case acquire one lock concurrently
heldThreadId = currentThreadId;
attemptLock.set(false);
}