[dmd-concurrency] shared arrays

Sean Kelly sean at invisibleduck.org
Thu Jan 14 07:21:23 PST 2010


On Jan 14, 2010, at 4:38 AM, Michel Fortin wrote:

> Le 2010-01-14 à 7:10, Steve Schveighoffer a écrit :
> 
>> 
>> What happens in cases like this:
>> 
>> shared(S)[] arr3;
>> arr3[] = arr2[];
>> 
>> any ideas of how this can be resolved?  Should shared arrays enjoy all the operations that normal arrays have?
> 
> Well, you need a lock.
> 
> Perhaps the runtime could maintain a shared pool of locks for those operations. You'd need to first hash the address of the allocated memory block (which is not necessary the first element, so you'll need the GC to tell you). This hash gives you the index of a mutex in the pool to use, the idea being that it's always the same mutex for a given memory block. Some memory blocks will share the same mutex, but if the pool is big enough two threads wanting the same mutex for a different memory block shouldn't happen too often.

Yeah, that's the other option.  Probably not too bad, since shared array ops should be fairly uncommon.


More information about the dmd-concurrency mailing list