std.concurrency : using delegate in lieu of function

Michel Fortin michel.fortin at michelf.com
Fri Aug 27 10:41:10 PDT 2010


On 2010-08-27 12:53:07 -0400, Gabriel Huau <contact at huau-gabriel.fr> said:

> void main()
> {
> 	Foo l = new Foo();
> 	void delegate() dg;
> 
> 	dg = &l.test;
> 	auto a = spawn(dg);
> 
> 	a.send("test");
> }
> 
> I have tested and it worked.

But by passing the this pointer of your Foo object to another thread, 
you've broken the rules about sharing memory between threads.

If Foo was a shared or synchronized type, then this could be made to 
work safely (with some adaptation to make the compiler aware of what 
delegates can be safely shared.)


-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/



More information about the Digitalmars-d mailing list