[dmd-concurrency] std.concurrency

Igor Lesik curoles at yahoo.com
Thu Feb 25 00:01:09 PST 2010


Sean has a way better understanding than me, I do not think I can contribute much.

Anyway, I have one small idea, I think we can safely get rid of receiveTimeout. See, receive() assumes
that parameters are delegates, so if first parameter is integral then we handle it as a special case and
conclude that it represents timeout. I have changed receive to:

bool receive(T...)(T ops) if (T.length > 0)
{
    static if(isIntegral!(T[0])) {
        long timeout = ops[0];
        const opBegin = 1;
    }
    else {
        long timeout = long.max;
        const opBegin = 0;
    }

    return
    theTid.mbox.get(
        timeout,
        (Variant val)
        {
            foreach (i, param; TypeTuple!(T[opBegin .. $]))

and it seems to work just fine:

        for (bool fun = true; fun; )
        {
            auto gotMessage = receive(
                2_000_000,
                &handleString,
                (int val){ writeln("Got int: ", val); },
                (byte b, long l){ writefln("Got (byte,long): (%d,%d)", b, l); },
                (float f, double d){ writefln("Got (float,double): (%f,%f)", f, d); },
                &skipIt,
                &catchIt,
                (bool gun){ fun = gun; }
            );
            if (!gotMessage)
                writeln("Timeout!");
        }



----- Original Message ----
From: Andrei Alexandrescu <andrei at erdani.com>
To: Discuss the concurrency model(s) for D <dmd-concurrency at puremagic.com>
Sent: Sun, February 21, 2010 10:52:48 AM
Subject: Re: [dmd-concurrency] std.concurrency

Igor Lesik wrote:
> Good. Then I will stop working on it.

Just until you coordinate with Sean. I'm sure your contribution would add a lot of value. Also, don't forget - new ideas are always appreciated!

> Andrei, I have a question, if you do not mind.  I understood that receiveOnly call
> is blocking, correct?

Correct.


Andrei
_______________________________________________
dmd-concurrency mailing list
dmd-concurrency at puremagic.com
http://lists.puremagic.com/mailman/listinfo/dmd-concurrency



      


More information about the dmd-concurrency mailing list