I don’t understand how
assert(ref.get() === thread) { "reentrancy is not supported" }
works.
If
if (ref.compareAndSet(null, thread)) {
goes to the else branch then ref.get() may return
- either another
Threadreference (which holds the lock currently), so theassert()will fail - or it may return even
null(if the lock was unlocked between theifand theref.get()calls), so theassert()will also fail