[dmd-concurrency] shared arrays

Sean Kelly sean at invisibleduck.org
Thu Jan 14 07:33:48 PST 2010


On Jan 14, 2010, at 7:27 AM, Steve Schveighoffer wrote:
> 
> This does not work:
> 
> shared(char)[] x;
> 
> void foo()
> {
>   shared(char)[] y = x;
>   y[] = "hi"; // how does this now lock the 1 bit in x?
> }

Yeah, the atomic ops were just for "shared char[]", ie. for updating the reference itself. You're right that the data has to be locked for data-level updates.  And slices, pointers, etc, make this a big problem for automatic locking.

> You'd need to lock the array data itself.  But in any case, I think it may be too ideal to think we can support atomic array operations without manual synchronization.  I.e., a SynchronizedArray type similar to UniqueArray type may be required for this.
> 
> I was thinking more in the case, how to write the runtime so it handles atomic updates of the actual array data, meaning at least word-sized data isn't messed up.  I have no idea if things like this should be possible on shared arrays:
> 
> a[] = b[] + 5 + c[];

I don't know that they can be, sadly.


More information about the dmd-concurrency mailing list