digitalmars.D.learn - std.concurrency and const
- =?UTF-8?Q?Christian_K=c3=b6stlin?= (68/68) Jan 05 2022 Hi all,
- frame (5/11) Jan 05 2022 They do. You have an error:
- =?UTF-8?Q?Christian_K=c3=b6stlin?= (4/16) Jan 06 2022 Duh ... you are right, my mistake!!!
Hi all, I really like std.concurrency but I now stumbled upon the following. When receiving messages as const, they also need to be sent as const (otherwise they are not matched). Comparing this to normal function calls I would expect a different behavior. ```d import std.concurrency; import std.stdio; struct Message { } void fun(const(Message) m) { writeln("fun(const(Message))"); } /* void fun(Message m) { writeln("fun(Message)"); } */ void receiver() { receive( (Tid sender, const(Message) m) { writeln("received const(Message)"); }, (const(Variant) v) { writeln("Received const(Variant)", v); }, (Variant v) { writeln("Received variant", v); }, ); writeln("done"); } int main(string[] args) { auto blubTid = spawnLinked(&receiver); blubTid.send(Message()); receive( (LinkTerminated t) { } ); fun(Message()); fun(const(Message)()); return 0; } ``` output is something like: ``` Received variantMessage() done fun(const(Message)) fun(const(Message)) ``` whereas I would expect ``` received const(Message) done fun(const(Message)) fun(const(Message)) ``` Looking forward for the explanation of that. Kind regards and happy 2022! Christian
Jan 05 2022
On Wednesday, 5 January 2022 at 22:22:19 UTC, Christian Köstlin wrote:Hi all, I really like std.concurrency but I now stumbled upon the following. When receiving messages as const, they also need to be sent as const (otherwise they are not matched). Comparing this to normal function calls I would expect a different behavior.They do. You have an error: `Message` doesn't match with `(Tid sender, const(Message) m)`. You don't get the argument `sender` here.
Jan 05 2022
On 2022-01-06 02:55, frame wrote:On Wednesday, 5 January 2022 at 22:22:19 UTC, Christian Köstlin wrote:Duh ... you are right, my mistake!!! Thanks! ChristianHi all, I really like std.concurrency but I now stumbled upon the following. When receiving messages as const, they also need to be sent as const (otherwise they are not matched). Comparing this to normal function calls I would expect a different behavior.They do. You have an error: `Message` doesn't match with `(Tid sender, const(Message) m)`. You don't get the argument `sender` here.
Jan 06 2022