March 27, 2012
Hello,

This question was posted in D.learn, but did not receive any answer. I apologize if this is not the right place to post.

I need to pass objects of a hierarchy between threads and I have some troubles.

The sample code below displays:
Unknown
B.fun()

I do not understand why an object of type A is fetched as a Variant, while a object of type B is received correctly.

Instead of
	(A a){a.fun();}
I also tried
	(immutable(A) a){a.fun();}
which resulted in
core.exception.AssertError@/usr/include/d/dmd/phobos/std/variant.d(286):
immutable(A)

Any idea?
I am using dmd 2.057 with linux.

Thanks

import std.stdio;
import std.concurrency;

class A{
	public:
		void fun()const{
			writeln("A.fun()");
		}
};
class B : A{
	public:
		override void fun()const{
			writeln("B.fun()");
		}
};

void producer(Tid t){
	auto a = new immutable(A);
	auto b = new immutable(B);
	t.send(a);
	t.send(b);
}

void main(){
	auto t = spawn(&producer, thisTid);
	while(1){
		receive(
			(A a){a.fun();},
			(Variant v){writeln("Unknown");}
			);
	}
}