Immutable
harakim via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Jun 23 07:25:48 PDT 2017
I am building a system where one thread generates commands and
sends them to another thread. The commands will never change once
they are created. I have marked the values immutable, but I've
been struggling to understand the requirements for sharing a
variable across threads.
cannot implicitly convert expression (new AppendChatCommand(type,
text)) of type data.messages.AppendChatCommand to
immutable(AppendChatCommand)
I'm trying to do this:
immutable(AppendChatCommand) command = new
AppendChatCommand(type, text);
send(childTid, command); //Compiler does not like command if it's
not immutable or shared (and I won't be modifying it or using it
in this thread)
The commands are generated and send as messages to the child. I
will never even use them again in the parent thread. What is the
easiest way to do this? Do I need to mark the class somehow?
I can provide a contrived example if necessary.
More information about the Digitalmars-d-learn
mailing list