Does anyone understand how to use "shared" types with concurrency send/receive functions?
Arek via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Aug 15 14:27:49 PDT 2017
On Tuesday, 15 August 2017 at 10:37:08 UTC, Kagamin wrote:
> Well, no wrapper is actually needed here:
>
> class A
> {
> int method() shared;
> }
>
> void consumer()
> {
> shared a = receiveOnly!(shared A)();
> }
>
> void producer()
> {
> auto cons = spawn(&consumer);
> send(cons, new shared A());
> }
Yes, but this doesn't compile:
import std.stdio;
import std.concurrency;
struct A
{
int t;
int r;
int method() shared
{
return 0;
}
}
void consumer()
{
shared a = receiveOnly!(shared A)();
}
void main()
{
auto cons = spawn(&consumer);
send(cons, shared A());
}
This very simple code also doesn't compile:
shared struct S
{
int i;
~this()
{
}
}
void main()
{
shared s = shared S();
}
In general, shared structs with postblit and destructor make
problems.
Arek
More information about the Digitalmars-d-learn
mailing list