sending shared pointer to struct. message type mismatch
ag0aep6g via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Apr 21 10:33:32 PDT 2016
On 21.04.2016 19:10, jacob wrote:
> private void runner(T)()
> {
> shared(T*) s = receiveOnly!(shared(T*))();
This tries to receive a `shared(S!(M, 2)*)`.
> writeln(s.x.length);
> writeln(s.x[0]);
> send(thisTid, true);
Aside: Should be `ownerTid` here, no?
> }
>
> int main(string[] argv)
Aside: If you don't use them, you don't need to the `int` return type
and parameter on main. A `void main()` works just fine.
> {
> alias S!(M, 2) TS;
> alias shared(TS*) PS;
Aside: preferred syntax nowadays is `alias TS = S!(M, 2);`.
>
> Tid runnerTid = spawn(&runner!(TS));
>
> auto s = new shared(TS);
This creates a `shared(S!(M, 2))*`, which is not exactly the same as
`shared(S!(M, 2)*)`. The pointer is not shared in the former, but it is
shared in the latter.
I was going to suggest either sending a `shared(TS*)` or receiving a
`shared(T)*`. But it looks like you can't send a shared pointer. When I
tried, it got turned into a unshared-pointer-to-shared on the way.
Changing it to `shared(T)*` on the receiving end works, though. Do that,
I guess.
> s.x[0] = M(42);
> send(runnerTid, s);
>
> bool ok = receiveOnly!bool();
>
> return 0;
> }
More information about the Digitalmars-d-learn
mailing list