On 2/2/20 12:13 PM, cc wrote:
On Friday, 31 January 2020 at 15:47:26 UTC, Steven Schveighoffer wrote:
You could use RefCounted to build a struct that then is sendable with the data you need. RefCounted allocates using C malloc, not the GC.

Thanks for the tips.  How exactly would I go about sending a RefCounted value?

static struct Foo {
     int a;
     @disable this(this);
}
auto t = RefCounted!Foo(Foo(5));
tid.send(t);

Gives me: phobos\std\concurrency.d(625): Error: static assert: "Aliases to mutable thread-local data not allowed."

Whereas trying to declare it as immutable gives me a pile of errors including: Error: mutable method `std.typecons.RefCounted!(int, cast(RefCountedAutoInitialize)1).RefCounted.__postblit` is not callable using a `immutable` object


Ugh, I think it should be doable. But I don't have time right now to try and figure it out.

The idea would be to send an immutable/shared piece of data that's refcounted across to another thread. If send is rejecting that, or refCounted is not playing nice, maybe file some bugzilla issues.

-Steve

Reply via email to