sending shared pointer to struct. message type mismatch

jacob via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Apr 21 10:10:31 PDT 2016


Hello!

I try to send shared pointer to struct:

[code]
import std.stdio;
import std.concurrency;

shared struct S(T, uint M)
{
	T[M] x;
}

shared struct M
{
	int x;
}


private void runner(T)()
{
	shared(T*) s = receiveOnly!(shared(T*))();
	writeln(s.x.length);
	writeln(s.x[0]);
	send(thisTid, true);
}

int main(string[] argv)
{
	alias S!(M, 2) TS;
	alias shared(TS*) PS;

	Tid runnerTid = spawn(&runner!(TS));

	auto s = new shared(TS);
	s.x[0] = M(42);
	send(runnerTid, s);

	bool ok = receiveOnly!bool();

	return 0;
}
[/code]

But after evaluating line "shared(T*) s = 
receiveOnly!(shared(T*))();" I get an exception:

"First-chance exception: std.concurrency.MessageMismatch 
Unexpected message type: expected 'shared(S!(M, 2u)*)', got 
'shared(engine.S!(M, 2u).S)*' at std\concurrency.d(224)"

How can I pass shared pointer to "runner" thread correctly?


More information about the Digitalmars-d-learn mailing list