[dmd-concurrency] shared arrays

Michel Fortin michel.fortin at michelf.com
Thu Jan 14 04:38:48 PST 2010


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.

The copy operation can't take any other lock though, or else you risk having deadlocks. This might be a problem when copying a struct.

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/





More information about the dmd-concurrency mailing list