February 05, 2011
On 4/02/11 11:44 PM, Sean Kelly wrote:
> Peter Alexander Wrote:
>>
>> How would you do it with message passing though? As I understand, all of
>> the std.concurrency message passing routines are blocking, and I need
>> this to be asynchronous.
>
> What do you mean by blocking?  The receive call will block until a message matching one of the supplied types arrives, but if you don't like this you can always use receiveTimeout.  send() doesn't deep copy objects, so the only reference types send() will currently accept are those labeled as shared or immutable (Unique!T will probably be added at some point, which is more appropriate for your situation).  So to use send() known unique reference data you'll have to cast to/from shared or immutable.  Nasty, but it'll work.

That's what I meant by blocking (receive).

Is using receiveTimeout with a timeout of 0 seconds the D-way of asynchronous message passing? (seems a bit hacky to me).

Thanks for your reply.
February 05, 2011
On Sat, 05 Feb 2011 20:42:53 +0300, Peter Alexander <peter.alexander.au@gmail.com> wrote:

> On 5/02/11 12:11 AM, Sean Kelly wrote:
>> Peter Alexander Wrote:
>>>
>>> Things might be easier if the error messages associated with D's
>>> concurrent features weren't especially unhelpful (for example, trying to
>>> spawn a thread with reference type parameters just gives you a 'no match
>>> for spawn template' error). It's nice that it stops you from doing such
>>> things, but it would be nice if it told me why it's not going to let me
>>> do them.
>>
>> Could you provide an example?  When passing reference data, the error you should see is: "Aliases to mutable thread-local data not allowed."  It's a static assert inside send().
>
> Now that I've investigated a bit more, it appears to be unrelated to reference types, and instead was an error about using a nested function:
>
> import std.concurrency;
> void main()
> {
>    void foo() {}
>    spawn(&foo);
> }
>
> ---
> test.d(5): Error: template std.concurrency.spawn(T...) does not match any function template declaration
> test.d(5): Error: template std.concurrency.spawn(T...) cannot deduce template function from argument types !()(void delegate())
> ---
>
> Why does it think that the function is a delegate?

Because even though foo doesn't use any of the local variables (nor does main declare any), it still has frame pointer as if it was using some:

void main()
{
    int x = 42;
    void foo() { printf("%d", x); }
    spawn(&foo);
}
February 05, 2011
On 02/05/2011 06:42 PM, Peter Alexander wrote:
> On 5/02/11 12:11 AM, Sean Kelly wrote:
>> Peter Alexander Wrote:
>>>
>>> Things might be easier if the error messages associated with D's
>>> concurrent features weren't especially unhelpful (for example, trying to
>>> spawn a thread with reference type parameters just gives you a 'no match
>>> for spawn template' error). It's nice that it stops you from doing such
>>> things, but it would be nice if it told me why it's not going to let me
>>> do them.
>>
>> Could you provide an example? When passing reference data, the error you
>> should see is: "Aliases to mutable thread-local data not allowed." It's a
>> static assert inside send().
>
> Now that I've investigated a bit more, it appears to be unrelated to reference
> types, and instead was an error about using a nested function:
>
> import std.concurrency;
> void main()
> {
> void foo() {}
> spawn(&foo);
> }
>
> ---
> test.d(5): Error: template std.concurrency.spawn(T...) does not match any
> function template declaration
> test.d(5): Error: template std.concurrency.spawn(T...) cannot deduce template
> function from argument types !()(void delegate())
> ---
>
> Why does it think that the function is a delegate?

In complement to what Denis Koroskin answered: when a func is defined inside another one, taking what looks like a func pointer to it automatically turns the result into a delegate.
I also find this annoying, even more because there is no automagic func* <--> delegate cast.

What I would like id:
* No func* / delegate distinction on the user side (can be impl optimisation if significant).
* Function auto-de/referencing: meaning in your code: spawn(foo).

Denis
-- 
_________________
vita es estrany
spir.wikidot.com

1 2
Next ›   Last »