Possible to pass a member function to spawn?
Steven Schveighoffer
schveiguy at yahoo.com
Mon Feb 6 18:33:18 PST 2012
On Mon, 06 Feb 2012 21:26:02 -0500, James Miller <james at aatch.net> wrote:
> It is also worth noting that the reason delegates are not eligible for
> thread spawn is that delegates hold references from outside their
> definition. This means that delegates can hold references to data that
> outside their thread, thus breaking the rule that all data is
> thread-local unless specified otherwise.
>
> The compiler could try to reason about your program and figure out
> that your "delegate" doesn't actually access cross-thread data, but
> that is very, very hard to prove. D's design is not suited to the
> Actor model, at least not without some modification.
He wants to do a delegate of a method from a shared class, there is no
unknown context here. I agree delegate literals should not be eligible.
Then again, those delegates should not be marked shared.
When I tried to run a simple test, the compiler reported:
Error: template std.concurrency.spawn(T...) cannot deduce template
function from argument types !()(void delegate() shared)
So clearly, the compiler knows that the delegate is from a shared object.
This should be doable today...
-Steve
More information about the Digitalmars-d
mailing list