Write barrier in ArrayList.grow()

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Write barrier in ArrayList.grow()

JSR166 Concurrency mailing list
Why wouldn't ArrayList add a write barrier in it's grow() method between the new elementData array population and the assignment of the elementData field? It would cost almost nothing, but exclude an important class of races, when one thread adds elements into an ArrayList, and other threads read elements at small indexes.

_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest
Reply | Threaded
Open this post in threaded view
|

Re: Write barrier in ArrayList.grow()

JSR166 Concurrency mailing list
Because a write barrier means nothing without a read barrier (which would need doing always). Then need a specification of which read synchronizes-with which write.


Alex

> On 12 Sep 2018, at 11:08, Roman Leventov via Concurrency-interest <[hidden email]> wrote:
>
> Why wouldn't ArrayList add a write barrier in it's grow() method between the new elementData array population and the assignment of the elementData field? It would cost almost nothing, but exclude an important class of races, when one thread adds elements into an ArrayList, and other threads read elements at small indexes.
> _______________________________________________
> Concurrency-interest mailing list
> [hidden email]
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest

_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest
Reply | Threaded
Open this post in threaded view
|

Re: Write barrier in ArrayList.grow()

JSR166 Concurrency mailing list
I don't understand, why read barriers are needed there? Constructors of classes with final fields don't require it, as far as I know. What I talk about, equivalently, is Arrays.copyOf() having safe publication semantics.

On Wed, 12 Sep 2018, 13:16 Alex Otenko, <[hidden email]> wrote:
Because a write barrier means nothing without a read barrier (which would need doing always). Then need a specification of which read synchronizes-with which write.


Alex

> On 12 Sep 2018, at 11:08, Roman Leventov via Concurrency-interest <[hidden email]> wrote:
>
> Why wouldn't ArrayList add a write barrier in it's grow() method between the new elementData array population and the assignment of the elementData field? It would cost almost nothing, but exclude an important class of races, when one thread adds elements into an ArrayList, and other threads read elements at small indexes.
> _______________________________________________
> Concurrency-interest mailing list
> [hidden email]
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest


_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest