Asynchronicity in D

Jonas Drewsen jdrewsen at nospam.com
Thu Mar 31 12:35:43 PDT 2011


On 31/03/11 18.26, Andrei Alexandrescu wrote:
> On 3/31/11 6:35 AM, Max Klyga wrote:
>> I've been thinking on things I can change in my GSoC proposal to make it
>> stronger and noticed that currently Phobos does not address asynchronous
>> I/O of any kind.
>>
>> A number of threads on thid newsgroup mentioned about this problem or
>> shown ways other languages address asynchronicity.
>>
>> I want to ask D community about plans on asynchronicity in Phobos.
>> Did somenone in Phobos team thought about possible design?
>> How does asynchronicity stacks with ranges?
>> What model should D adapt?
>> etc.
>
> I think that would be a good contribution that would complement Jonas'.
> You'll need to discuss cooperation with him and at best Jonas would
> agree to become a mentor.
>
> I've posted a couple of weeks earlier how I think that could work with
> ranges: the range maintains the asynchronous state and has a queue of
> already-available buffers received. The network traffic occurs in a
> different thread; the range throws requests over the fence to libcurl
> and libcurl throws buffers over the fence back to the range. The range
> offers a seemingly synchronous interface:
>
> foreach (line; byLineAsync("http://d-programming-language.org"))
> {
> ... use line ...
> }
>
> except that the processing and the fetching of data occur in distinct
> threads.
>
> Server-side code such as network servers etc. would also be an
> interesting topic. Let me know if you're versed in the likes of libev(ent).
>
>
> Thanks,
>
> Andrei

I believe that we would need both the threaded async IO that you 
describe but also a select based one. The thread based is important e.g. 
in order to keep buffering incoming data while processing elements in 
the range (the OS will only buffer the number of bytes allowed by 
sysadmin). The select based is important in order to handle _many_ 
connections at the same time (think D as the killer app for websockets). 
As Robert mentions fibers would be nice to take into consideration as well.

What I also see as an unresolved issue is non-blocking handling in 
http://erdani.com/d/phobos/std_stream2.html which fits in naturally with 
this topic I think.

I may very well agree mentoring if we get a solid proposal out of this.

/Jonas


More information about the Digitalmars-d mailing list