Thread overview
Sending Tid in a struct
Mar 03, 2012
Nicolas Silva
Mar 03, 2012
Timon Gehr
Nov 23, 2016
Christian Köstlin
Sep 29, 2018
Chris Katko
March 03, 2012
Hi,

I'm trying to send structs using std.concurrency. the struct contains a Tid (the id of the sender) so that the receiver can send an answer.

say:

struct Foo
{
  Tid tid;
  string str;
}

// ...

Foo f = {
  tid: thisTid,
  str: "hello!"
};
std.concurrency.send(someThread, f);
// /usr/include/d/dmd/phobos/std/concurrency.d(465): Error: static
assert  "Aliases to mutable thread-local data not allowed."
// hello.d(15):        instantiated from here: send!(Foo)

However, I can send a Tid if I pass it directly as a parameter of the send function instead of passing it within a struct.

Is this a bug ? It looks like so to me but I guess I could have missed something.

thanks in advance,

Nicolas
March 03, 2012
On 03/03/2012 12:09 PM, Nicolas Silva wrote:
> Hi,
>
> I'm trying to send structs using std.concurrency. the struct contains
> a Tid (the id of the sender) so that the receiver can send an answer.
>
> say:
>
> struct Foo
> {
>    Tid tid;
>    string str;
> }
>
> // ...
>
> Foo f = {
>    tid: thisTid,
>    str: "hello!"
> };
> std.concurrency.send(someThread, f);
> // /usr/include/d/dmd/phobos/std/concurrency.d(465): Error: static
> assert  "Aliases to mutable thread-local data not allowed."
> // hello.d(15):        instantiated from here: send!(Foo)
>
> However, I can send a Tid if I pass it directly as a parameter of the
> send function instead of passing it within a struct.
>
> Is this a bug ? It looks like so to me but I guess I could have missed
> something.
>
> thanks in advance,
>
> Nicolas

Yes, this seems to be a bug.

Workaround:

struct Foo{
    string s;
    Tid id;
}

void foo(){
    Foo foo;
    receive((Tuple!(string,"s",Tid,"id") bar){foo=Foo(bar.s,bar.id);});
}

void main(){
    auto id = spawn(&foo);
    id.send("string",id);
    ...
}
November 23, 2016
On 03/03/2012 18:35, Timon Gehr wrote:
> On 03/03/2012 12:09 PM, Nicolas Silva wrote:
>> Hi,
>>
>> I'm trying to send structs using std.concurrency. the struct contains a Tid (the id of the sender) so that the receiver can send an answer.
>>
>> say:
>>
>> struct Foo
>> {
>>    Tid tid;
>>    string str;
>> }
>>
>> // ...
>>
>> Foo f = {
>>    tid: thisTid,
>>    str: "hello!"
>> };
>> std.concurrency.send(someThread, f);
>> // /usr/include/d/dmd/phobos/std/concurrency.d(465): Error: static
>> assert  "Aliases to mutable thread-local data not allowed."
>> // hello.d(15):        instantiated from here: send!(Foo)
>>
>> However, I can send a Tid if I pass it directly as a parameter of the send function instead of passing it within a struct.
>>
>> Is this a bug ? It looks like so to me but I guess I could have missed something.
>>
>> thanks in advance,
>>
>> Nicolas
> 
> Yes, this seems to be a bug.
> 
> Workaround:
> 
> struct Foo{
>     string s;
>     Tid id;
> }
> 
> void foo(){
>     Foo foo;
>     receive((Tuple!(string,"s",Tid,"id") bar){foo=Foo(bar.s,bar.id);});
> }
> 
> void main(){
>     auto id = spawn(&foo);
>     id.send("string",id);
>     ...
> }
I had a similar problem with this an it seems this is still a bug with dmd 2.072.

best regards,
christian


September 29, 2018
On Wednesday, 23 November 2016 at 08:47:56 UTC, Christian Köstlin wrote:
> On 03/03/2012 18:35, Timon Gehr wrote:
>> On 03/03/2012 12:09 PM, Nicolas Silva wrote:
>>> [...]
>> 
>> Yes, this seems to be a bug.
>> 
>> Workaround:
>> 
>> struct Foo{
>>     string s;
>>     Tid id;
>> }
>> 
>> void foo(){
>>     Foo foo;
>>     receive((Tuple!(string,"s",Tid,"id") bar){foo=Foo(bar.s,bar.id);});
>> }
>> 
>> void main(){
>>     auto id = spawn(&foo);
>>     id.send("string",id);
>>     ...
>> }
> I had a similar problem with this an it seems this is still a bug with dmd 2.072.
>
> best regards,
> christian

So this appears to still be a bug in 2.078.0-beta.1. Sigh...

So the only way to actually use concurrency in D... is to use this hack? Or has it been fixed since January? Is there an official bug report?