Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

user defined struct can't be passed through tid.send

I have created a mutlithreaded simulator that relies heavily on the native message passing between threads (don't go telling me to go single threaded it's for my thesis on D and I need to get this to work)

after a very durty kludge involving a lot of casts of objects to and from shared. which prolly had some ugly race condition bugs. I decided to create an opaque type that represents an object that can receive messages that should be able to be passed around without all that casting...

no such luck

struct OpaqueFaseSim{
    Tid tid;
    void send(...){...}
}

void foo(){
Tid tid;
long time;
    OpaqueFaseSim ofs;
    //...
    tid.send(ofs,time);//Error: static assert  "Aliases to mutable thread-local data not allowed."
}

why can I pass a Tid around but not a struct containing only a Tid?

and how can I fix this

like image 481
ratchet freak Avatar asked May 12 '11 21:05

ratchet freak


1 Answers

I think it's because Tid has a MessageBox field which is a class type.

You can type OpaqueFaseSim's tid field as shared or ___gshared and it will work:

struct OpaqueFaseSim{
    Bar bar;
    shared Tid tid;
    // __gshared Tid tid;
}
like image 71
Andrej Mitrović Avatar answered Nov 20 '22 10:11

Andrej Mitrović