Concurrency message passing
Steven Schveighoffer
schveiguy at gmail.com
Tue Aug 17 12:24:14 UTC 2021
On 8/17/21 7:05 AM, JG wrote:
> Hi
>
> I have a program with two threads. One thread produces data that is put
> in a queue
> and then consumed by the other thread. I initially built a custom queue
> to do this, but thought this should have some standard solution in D? I
> looked at std.concurrency and thought that message passing could be
> used. However, the problem is that I get the following error.
>
> Error: static assert: "Aliases to mutable thread-local data not allowed."
>
> I am not sure how to solve this. Maybe message parsing isn't the
> correct solution?
> Is there some standard solution to this in D?
Data with references needs to be marked either immutable or shared in
order to be passed using std.concurrency. D is strict about not sharing
thread-local data, because then you can use the type system to prove
lock-free code is valid.
However, data that has no references (aliases) should be passable
regardless of mutability, because you are passing a copy.
-Steve
More information about the Digitalmars-d-learn
mailing list