[concurrency-interest] how to use Thread.yield to fix ConcurrentIntArrayList

Brian S O'Neill bronee at gmail.com
Tue Jan 9 15:00:46 EST 2018


Your comment on the "ar" field suggests that you expect stores into the 
array to behave as volatile stores. This isn't the case. Only the 
pointer to ar itself is volatile. I think you want a final reference to 
an AtomicIntegerArray instead.

On 2018-01-09 08:48 AM, Andrew Nuss via Concurrency-interest wrote:
> I have written a growable concurrent array list of ints.  For stats accumulation.  I think its ok, except for the issue
> that it must currently be used by threads of the same priority or there could be deadlock due to a lower priority thread
> changing the "ref" in a temporary way in the add() function, and not being able to complete the final set due to a higher
> priority thread also for example starting an add() and looping waiting for the final set to occur.
> 
> Any ideas on how to fix, such as using Thread.yield() in some effective way?
> 
> Or is there something already out there that does this?
> 
> public class ConcurrentIntArrayList {
>      private static final int DEFAULT_CAPACITY = 16;
> 
>      private static class MyArray {
>          private volatile int[] ar;  // effectively final, but volatile to flush elem values between cores
> 


More information about the Concurrency-interest mailing list