[dmd-concurrency] shared arrays
Steve Schveighoffer
schveiguy at yahoo.com
Thu Jan 14 07:27:37 PST 2010
----- Original Message ----
> From: Sean Kelly <sean at invisibleduck.org>
> On Jan 14, 2010, at 4:10 AM, Steve Schveighoffer wrote:
>
> > Having implemented the array append patch to fix stomping, and reading the
> dmd-concurrency debate, I realized that what I implemented is no good for shared
> arrays.
> >
> > In fact, I wonder how shared arrays can support any array operations
>
> I sent an email about this a while back. In short, if we're going to allow
> array ops on shared arrays at all I think they'll have to use atomic ops to
> "lock" the array for the length of the update. Basically, set the 1 bit of the
> ptr field to indicate the array is locked. This gets tricky when more than one
> shared array is involved because the lock has to be acquired on each, and
> because different ops may try to lock arrays in different orders, if a spinlock
> acquire times out the code will have to release all the locks it's acquired,
> wait some random interval, and try again. Pretty complicated stuff if the goal
> is just to support shared array ops.
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?
}
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[];
The simple case of data copying may be acceptable, since you simply want to do a shared read of each data item, and a shared write to the target.
But in any case, I don't know how to handle cases where data is a hybrid -- some data shared and some not shared.
-Steve
More information about the dmd-concurrency
mailing list