Primitive Queue<any T> considerations
john.r.rose at oracle.com
Thu Nov 19 01:18:45 UTC 2015
On Nov 18, 2015, at 11:15 AM, Timo Kinnunen <timo.kinnunen at gmail.com> wrote:
> That’s a good question. How would arbitrary-sized values be assigned into an array without any other thread observing the value halfway between two states with its invariants not holding?
Yes, it is a very good question. The basic tools are buffering (pointer-swapping),
locking (e.g., seq-locks, maybe split along array chunks), freezing (safe publication),
and thread confinement (including existing object synch infra). Plus whatever
acceleration the hardware can give for simple transactions (TSX, HLE).
Plus working carefully with user expectations, as we do today with the
related issue of object tearing (ArrayList might tear, String won't).
It will require experimentation to find the best combination of these measures.
I have to give props to Jeroen Fritjers on this; when I described the 2012 version of
values to him he immediately zeroed in on the problem of array element atomicity.
P.S. FTR, some background info on tearing (not array-specific) is here:
More information about the valhalla-dev