开发者

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 b开发者_如何学Pythone 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


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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜