User-defined structure cannot be passed through tid.send

I created a mutlithreaded simulator that relies heavily on a native message passing between threads (don't tell me to skip one thread for my D dissertation, and I need to get this to work)

after a very long kludge, including many castings of objects in shared and vice versa. who had pretty ugly race condition errors. I decided to create an opaque type representing an object that can receive messages that can be transmitted without any 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, but not a structure containing only Tid?

and how can i fix it

+6
source share
1 answer

I think because Tid has a MessageBox field, which is a type of class.

You can enter a field of type OpaqueFaseSim as general or ___gshared, and it will work:

 struct OpaqueFaseSim{ Bar bar; shared Tid tid; // __gshared Tid tid; } 
+2
source

Source: https://habr.com/ru/post/887972/


All Articles