The following is inspired by some discussions with John Rose
on how we might implement atomic access to value type "tuples" for subsequent JDK releases. As I understand it, the basic idea is to have something close C++'s atomic<POD>
Since reading (loading) a value type is expected to be the dominant mode of access, we'd like to use something like SeqLocks
so that readers don't have to write to any shared locations. (See also
). But at the same time we'd like writers to use something more civilized than a classic test-and-set single-bit SeqLock. To that end, we might use an Inflatable SeqLock
). Each tuple would have an associated inflatable word-sized SeqLock. That SeqLock reserves the low order 2 bits for writing and the remainder is the usual SeqLock version field. When writer threads are waiting, the remainder of the field points to the head of a stack of waiting threads and the version number is displaced, held by the eldest element on the stack.
Of course the implementation could use software transactional memory implementations (STMs) like TL2
, but that seems like overkill given that there's no intra-object consistency to be concerned with.