[dmd-concurrency] draft 4

Andrei Alexandrescu andrei at erdani.com
Tue Jan 12 14:00:22 PST 2010


Robert Jacques wrote:
> On Tue, 12 Jan 2010 03:45:35 -0500, Andrei Alexandrescu 
> <andrei at erdani.com> wrote:
>> To be found at the usual location:
>>
>> http://erdani.com/d/fragment.preview.pdf
>>
>> I didn't add a lot of text this time around but I do have a full 
>> example of communicating threads. Skip to the last section for 
>> explanation. I paste the code below. I think it looks pretty darn 
>> cool. Sean, please let me know if it floats your boat.
>>
>> import std.concurrency, std.stdio;
>>
>> void main() {
>>     auto low = 0, high = 1000;
>>     auto tid = spawn(&fun);
>>     foreach (i; low .. high) {
>>        writeln("Main thread: ", message, i);
>>        tid.send(thisTid, i);
>>        enforce(receiveOnly!Tid() == tid);
>>     }
>>     // Signal the other thread
>>     tid.send(Tid(), 0);
>> }
> 
> message is undefined and doesn't match the output. Is this a typo?

Yah, sorry. I'm writing code that won't compiled yet anyway :o). Thanks.

> I know this is a bit of a bike shed, but I'd prefer something shorter 
> for receiveOnly, (like recv or receive) as A) type-checked message 
> passing should be the easy/default way to do things and B) it's easy to 
> define recv!()() to return the unchecked message using a variant. I'd 
> also like to be able to use recv(tid,i); in addition to recv!(Tid, 
> int)(); but I haven't been able to get the templates to not clash with 
> each other.

As of now I'm thinking that receiveOnly will be much more rarely used 
than receive() with several dispatchers. receiveOnly is very restrictive 
- see my next message.


Andrei


More information about the dmd-concurrency mailing list