Zero timeout receive

James Wirth jwirth1 at suddenlink.net
Mon Apr 15 19:22:11 PDT 2013


On Saturday, 13 April 2013 at 08:54:03 UTC, John Colvin wrote:
> On Saturday, 13 April 2013 at 01:26:16 UTC, James Wirth wrote:
>> The discussion:
>>
>>    
>> http://forum.dlang.org/thread/mailman.426.1286264462.858.digitalmars-d@puremagic.com?page=9
>>
>> implies that:
>>   receiveTimeout(dur!"msecs"(0), some-callback-function)
>>
>> is acceptable - meaning that no blocking occurs.  A simple 
>> experiment verifies this - but I hesitate to use 
>> "undocumented" features.  Some APIs would interpret the 0 as 
>> infinity.
>>
>> I also fear that placing such a nonblocking recieve into the 
>> main event loop of a GUI program would impact performance - it 
>> would also be non-generic.  Is there a fast function which 
>> returns true just when the "mail box" is non-empty?
>>
>> Thanks
>
> Make a small test and time it. I personally wouldn't expect to 
> see much slowdown from the extra code invoked by receiveTimeout 
> compared to the rest of a busy loop.
>
> However, either special casing receiveTimeout for 0 duration or 
> introducing a new receiveNoBlock or similar would be good.

Im using wine on Linux to develop MS code (dont have an MS box) 
so am not too confident of timing accuracy - however, I tried it 
in the really simple MS GUI library Im making, and it seems to 
work ok.

Special casing receiveTimeout would introduce less name bloat but 
might impact other receive performance.  As a Java programmer I 
tend to ignore slowdowns of 2:1 and as a Python programmer even 
70:1 - but I could see that system programmers might disagree.

Thanks for your thoughts.


More information about the Digitalmars-d mailing list