[concurrency-interest] The atomicity of StampedLock lock conversion
mr.chrisvest at gmail.com
Fri Oct 10 06:12:08 EDT 2014
One might, without further research, come to be ostensibly reasonable conclusion that a read-write lock that offers lock conversion, would be able to convert a write-lock into a read-lock atomically.
Reading the documentation for the StampedLock#tryConvertToRead, we’re told that if given a write-lock stamp, the method will first release that write-lock, and then obtain a read-lock, thus leaving a window for someone else to grab the lock ahead of us.
This ends up being a bad thing in my case. My code can, however, also use optimistic read-locks just as well as the pessimistic read-lock, so I turn to StampedLock#tryConvertToOptimisticRead. I’m told that the write-lock will be released and that I’ll get an observation stamp. I am not told whether or not this transition is atomic. That is, if it’s possible for the lock to be taken and then released again, in between me releasing my write-lock and obtaining the observation stamp, in some sense, such that the observation stamp will validate when I ask about it later.
So that’s my question: Is StampedLock#tryConvertToOptimisticRead atomic in this respect?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Concurrency-interest