Associative arrays, multithreading, Rebindable

Jack Applegame japplegame at gmail.com
Sat Apr 12 01:22:21 PDT 2014


If I want to pass a dynamic array from one thread to another, 
then I use immutable(T)[] and it is safe.
But what if I need to pass an associative array? I suppose that 
the use of immutable(T)[U] is unsafe. Because one thread can 
delete the entry and this will have an impact also on the 
instance of the array in another thread.
So I have to use immutable(T[U]). But the immutability of the 
entire array makes the array reference immutable too:

immutable int[string] foo;
foo = assumeUnique(other); // error

For immutable classes we can use std.typecons.Rebindable:

Rebindable!(immutable Foo) foo;
foo = new immutable Foo; // fine

But for immutable associative arrays we can't:

Rebindable!(immutable int[string]) foo; // error
foo = assumeUnique(other);

Error: template instance 
std.typecons.Rebindable!(immutable(int[string])) does not match 
template declaration Rebindable(T) if (is(T == class) || is(T == 
interface) || isArray!T)

Should Rebindable to support associative arrays?


More information about the Digitalmars-d-learn mailing list