digitalmars.D.learn - std.concurrency.send problems with immutable
- Marek Janukowicz (49/49) Aug 07 2015 This program works fine:
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (10/39) Aug 07 2015 Yes, it is a bug. The reason the number of members makes a difference is...
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?
On a related note - sometimes when sending a shared struct I get a
compilation error similar to this:
/opt/dmd2/linux/bin64/../../src/phobos/std/variant.d(638): Error: function
core.stdc.string.memcpy (void* s1, const(void*) s2, ulong n) is not callable
using argument types (ubyte[32]*, shared(Notification)*, ulong)
/opt/dmd2/linux/bin64/../../src/phobos/std/variant.d(580): Error: template
instance std.variant.VariantN!32LU.VariantN.opAssign!(shared(Notification))
error instantiating
/opt/dmd2/linux/bin64/../../src/phobos/std/concurrency.d(117):
instantiated from here: __ctor!(shared(Notification))
/opt/dmd2/linux/bin64/../../src/phobos/std/concurrency.d(628):
instantiated from here: __ctor!(shared(Notification))
/opt/dmd2/linux/bin64/../../src/phobos/std/concurrency.d(618):
instantiated from here: _send!(shared(Notification))
/opt/dmd2/linux/bin64/../../src/phobos/std/concurrency.d(594):
instantiated from here: _send!(shared(Notification))
If I then add more fields to the struct (eg. dummy "string a,b") it compiles
fine.
Is this another bug or am I missing something?
--
Marek Janukowicz
Aug 07 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:templateinstance 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#L608On 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
Aug 07 2015








=?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com>