chen870647924 / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

Add volatile semantics to the count of CountingInput(Output)Stream #900

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I have several threads that might read from a shared CountingInputStream, but 
only If their internal counter is equal to the count of the stream. To actually 
read from the stream will of course require locking. However, if the count of 
the stream had volatile semantics I could avoid contention by utilising the 
double-checked locking pattern.

This might not be such a big an issue, but neither is adding volatile and some 
documentation?

Original issue reported on code.google.com by andreas....@gmail.com on 14 Feb 2012 at 11:47

GoogleCodeExporter commented 9 years ago

Original comment by wasserman.louis on 16 Feb 2012 at 6:28

GoogleCodeExporter commented 9 years ago

Original comment by fry@google.com on 13 Mar 2012 at 6:40

GoogleCodeExporter commented 9 years ago

Original comment by fry@google.com on 13 Mar 2012 at 6:40

GoogleCodeExporter commented 9 years ago
Arguably we should do this just to follow the precedent that streams are 
thread-safe, but I'm not sure that that's a precedent worth following.  (We'd 
have to go all the way to atomics.)

Original comment by cpov...@google.com on 13 Mar 2012 at 7:31

GoogleCodeExporter commented 9 years ago

Original comment by kevinb@google.com on 22 Jun 2012 at 6:16

GoogleCodeExporter commented 9 years ago
Issue 1256 has been merged into this issue.

Original comment by wasserman.louis on 13 Jan 2013 at 9:35

GoogleCodeExporter commented 9 years ago
If this issue is going to be resolved with a AtomicLong counter.
It would be really useful to have an addition constructor that takes the actual 
AtomicLong to call add on.
CountingOutputStream(AtomicLong counter, OutputStream);

Sometimes I need to count the totals across of a number of files.
Having to sum all the counting output stream are a bit annoying.

Original comment by kaspe...@gmail.com on 23 Jan 2013 at 4:16

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:14

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:18

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:08