[dmd-concurrency] shared arrays

Andrei Alexandrescu andrei at erdani.com
Wed Jan 27 18:33:42 PST 2010


Robert Jacques wrote:
> I did write down a simple single cas/xchg routine below, but it suffers 
> from tearing and inconsistencies if/when two or more writers assign to x.
> 
> Given:
> shared int[] x;
> shared int[] y;
> x = y;
> 
> Then:
> if(y.length < x.length) { // shrink then set
>    x.length = y.length;
>    x.ptr    = y.ptr;
> } else { // set then expand
>    x.ptr    = y.ptr;
>    x.length = y.length;
> }

Yah this is problematic because arrays go through states they aren't 
supposed to go through.

> So, my read on this is the given all 64-bit x86 CPUs support SSE2, 
> atomic reads/writes can be done using 128-bit SSE memory ops on aligned 
> data. So all that's needed is align(16) support in DMD (align(8) would 
> also be appreciated)

I've read about 128-bit SSE operations. I'm not sure to what extent we 
could rely on them being there. Besides, we'd need to make sure all 
arrays (or at least all shared arrays) are properly aligned. I'm open to 
this, but would like to collect more data and ideas if we're to commit 
working on this.


Andrei



More information about the dmd-concurrency mailing list