[concurrency-interest] COWList snapshot.

Jason Mehrens jason_mehrens at hotmail.com
Wed Feb 19 17:22:59 EST 2014

Vladimir, Mutable local scope snapshots are safe.  Clone and copy constructor both meet all of your initial requirements as long as you can resist temptation to modify your local snapshot.  COWAL is optimized for read so if you are concerned that a COWAL snapshot is going to be too slow for reading the COWAL should probably not be used at all. However, I would encourage you to give the clone and or copy constructor a try.  Let us know how it works out.  One can only assume the reason the 2009 thread died and we don't have a snapshot method today is that the alternatives work. http://brooker.co.za/blog/2012/09/10/volatile.html Jason Date: Wed, 19 Feb 2014 22:41:01 +0400
Subject: Re: [concurrency-interest] COWList snapshot.
From: ppozerov at gmail.com
To: jason_mehrens at hotmail.com
CC: concurrency-interest at cs.oswego.edu

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


2014-02-19 19:12 GMT+04:00 Jason Mehrens <jason_mehrens at hotmail.com>:


You can use the COWAL copy constructor which has a fast path for COWAL or use the clone method.



> 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                                      

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20140219/0e9256d9/attachment.html>

More information about the Concurrency-interest mailing list