[dmd-concurrency] shared arrays

Steve Schveighoffer schveiguy at yahoo.com
Thu Jan 28 04:08:53 PST 2010


b, with c being a fully usable implementation of b.  Reallocating an array on every assign is just as bad, if not worse, than taking a lock on an object.

Also, consider that assigning to the length of an array is bad news also, it's a function call.  I think straight shared arrays are a bad idea in general.

-Steve



----- Original Message ----
> From: Andrei Alexandrescu <andrei at erdani.com>
> 
> Consider a shared array:
> 
> shared int[] x;
> 
> What can be done with it? It's tricky; the array has two words worth of info and 
> we can't assume 128 bits can be atomically written on a 64-bit machine.
> 
> So you can't assign the entire array. If we assume no assignment, then element 
> access with bounds checking becomes possible. But then we need to provide a 
> method for changing a shared array. There are a few possibilities:
> 
> (a) recommend an extra indirection
> 
> shared int[]* x;
> 
> A pointer can be reassigned, so whenever you want to mess with the array you 
> reallocate it.
> 
> (b) recommend you put the array in a class
> 
> class A
> {
>     int[] x;
> }
> 
> Then, inside synchronized methods of shared(A) objects, the type of x changes 
> from shared(int[]) to shared(int)[] and can be manipulated.
> 
> (c) recommend the yet-unwritten class std.concurrency.SharedArray.
> 
> Any thoughts are welcome.
> 
> 
> Andrei
> _______________________________________________
> dmd-concurrency mailing list
> dmd-concurrency at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/dmd-concurrency



      


More information about the dmd-concurrency mailing list