Pass Tid[string] to another thread (by send)

TencoDK via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Aug 4 16:17:52 PDT 2016


Hi!

I'm trying to make threads communicate by sending an immutable 
address book to each thread.


Code:

Tid[string] addressBook;

addressBook["Some"] = sdfsdf;
addressBook["Input"] = sdfsdf;

auto sharedAddressBook = 
cast(immutable(Tid[string]))(addressBook);
send(tid, sharedAddressBook); // <- error


Output log:

C:\D\dmd2\windows\bin\..\..\src\phobos\std\variant.d(439): Error: 
cannot modify immutable expression (*zis)[args[1].get()]
C:\D\dmd2\windows\bin\..\..\src\phobos\std\variant.d(632): Error: 
template instance 
std.variant.VariantN!20LU.VariantN.handler!(immutable(int[immutable(string)])) error instantiating
C:\D\dmd2\windows\bin\..\..\src\phobos\std\variant.d(548):        
instantiated from here: 
opAssign!(immutable(int[immutable(string)]))
C:\D\dmd2\windows\bin\..\..\src\phobos\std\concurrency.d(117):    
     instantiated from here: 
__ctor!(immutable(int[immutable(string)]))
C:\D\dmd2\windows\bin\..\..\src\phobos\std\concurrency.d(639):    
     instantiated from here: 
__ctor!(immutable(int[immutable(string)]))
C:\D\dmd2\windows\bin\..\..\src\phobos\std\concurrency.d(629):    
     ... (1 instantiations, -v to show) ...
C:\D\dmd2\windows\bin\..\..\src\phobos\std\concurrency.d(605):    
     instantiated from here: 
_send!(immutable(int[immutable(string)]))
src\aelia\aelia.d(42):        instantiated from here: 
send!(immutable(int[immutable(string)]))
Building build\x64\Debug\AeliaD.exe failed!


variant.d:
...
else static if (isAssociativeArray!(A))
{
     (*zis)[args[1].get!(typeof(A.init.keys[0]))] // <- line 439
         = args[0].get!(typeof(A.init.values[0]));
     break;
}
...


What am I doing wrong? Is there a proper way to pass an 
associative array to another thread?

I also found a thread on the forum 
http://forum.dlang.org/post/mailman.209.1348312788.5162.digitalmars-d-learn@puremagic.com
that saying it is a bug in Variant, but that bug was fixed 
already. Have I found a new one? %)


Sincerely,
Alexey


More information about the Digitalmars-d-learn mailing list