std.concurrency.send problems with immutable

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Aug 7 15:56:35 PDT 2015


On 08/07/2015 03:24 PM, Marek Janukowicz wrote:> This program works fine:
 >
 > import std.concurrency;
 >
 > struct A {
 >    string a,b;
 > }
 >
 > void main () {
 >    immutable A a = immutable A( "blah" );
 >    send( thisTid, a );
 > }
 >
 > But if change struct A declaration to:
 >
 > struct A {
 >    string a,b,c;
 > }
 >
 > I get this error during compilation:
 > /opt/dmd2/linux/bin64/../../src/phobos/std/variant.d(653): Error: cannot
 > modify immutable expression *p
 > /opt/dmd2/linux/bin64/../../src/phobos/std/variant.d(580): Error: 
template
 > instance std.variant.VariantN!32LU.VariantN.opAssign!(immutable(A)) error
 > instantiating
 > /opt/dmd2/linux/bin64/../../src/phobos/std/concurrency.d(117):
 > instantiated from here: __ctor!(immutable(A))
 > /opt/dmd2/linux/bin64/../../src/phobos/std/concurrency.d(628):
 > instantiated from here: __ctor!(immutable(A))
 > /opt/dmd2/linux/bin64/../../src/phobos/std/concurrency.d(618):
 > instantiated from here: _send!(immutable(A))
 > /opt/dmd2/linux/bin64/../../src/phobos/std/concurrency.d(594):
 > instantiated from here: _send!(immutable(A))
 >
 > Is this is a bug?

Yes, it is a bug. The reason the number of members makes a difference is 
that Variant's implementation does different things depending on T.sizeof:

 
https://github.com/D-Programming-Language/phobos/blob/master/std/variant.d#L608

 > On a related note - sometimes when sending a shared struct I get a
 > compilation error similar to this:

Variant has a number of open bugs. Unfortunately, Variant reduces the 
quality of std.concurrency as Variant is used as a catch-all type by 
that module.

Ali



More information about the Digitalmars-d-learn mailing list