Does anyone understand how to use "shared" types with concurrency send/receive functions?

Kagamin via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Aug 16 03:20:46 PDT 2017


On Tuesday, 15 August 2017 at 21:27:49 UTC, Arek wrote:
> 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());
> }

AIU you use struct as a Unique-like wrapper for shared class 
object. Extract the object and send it, then wrap again on 
arrival.


More information about the Digitalmars-d-learn mailing list