[concurrency-interest] COWList snapshot.

Martin Buchholz martinrb at google.com
Wed Feb 19 14:55:16 EST 2014


Владимир,

I agree that a snapshot method as you propose would be useful.  As always,
implementing the List interface ends up being rather a lot of tedious work,
which may be a reason it never got done.


On Wed, Feb 19, 2014 at 10:41 AM, Владимир Озеров <ppozerov at gmail.com>wrote:

> Jason,
>
> The main problem with copying constructor is volatile access to array
> which is expected to be immutable. Furthermore COWList created from another
> COWList breaks snapshot semantics - it can be changed. The same applies for
> clone().
> Proposed wrapper should be pretty similar to COWIterator - thin wrapper
> with final array.reference inside. Old thread with example of this approach
> -
> http://cs.oswego.edu/pipermail/concurrency-interest/2009-March/005926.html
>
> Vladimir.
>
>
> 2014-02-19 19:12 GMT+04:00 Jason Mehrens <jason_mehrens at hotmail.com>:
>
> Vladimir,
>>
>> You can use the COWAL copy constructor which has a fast path for COWAL or
>> use the clone method.
>>
>> Jason
>>
>> ________________________________
>> > Date: Wed, 19 Feb 2014 18:21:14 +0400
>> > From: ppozerov at gmail.com
>> > To: concurrency-interest at cs.oswego.edu
>> > Subject: [concurrency-interest] COWList snapshot.
>> >
>> > Hi,
>> >
>> > I was a little bit suprized when found that there is no convenient way
>> > to get snapshot of COW list.
>> > .
>> > What I need is to get snapshot of the list (in form of either array or
>> > List, doesn't matter) and perform several reads on it (index lookups or
>> > traversals). For this reason I cannot use iterator. Also I would like
>> > to avoid unnecessary array copying since I'm not going to perform
>> > writes. So getting internal array appears to be the best way to do that
>> > from performance perspective. Copying constructor and forEach() method
>> > already employ this technique in JDK8
>> > (
>> http://gee.cs.oswego.edu/cgi-bin/viewcvs.cgi/jsr166/src/main/java/util/concurrent/CopyOnWriteArrayList.java?view=markup
>> )
>> >
>> > For now there is no way to get that array since all access to it are
>> > either private or package-scoped. Could something like "List<T>
>> > snapshot()" be added to COWList API returning unmodifiable wrapper over
>> > internal array? Or at least getArray() could be made protected so that
>> > developers can use it on their own risk :-)
>> >
>> > Vladimir.
>> >
>> > _______________________________________________ Concurrency-interest
>> > mailing list Concurrency-interest at cs.oswego.edu
>> > http://cs.oswego.edu/mailman/listinfo/concurrency-interest
>>
>
>
>
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20140219/4b78dffd/attachment.html>


More information about the Concurrency-interest mailing list