flush MessageBox

Chris via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Aug 21 08:04:08 PDT 2015


On Friday, 21 August 2015 at 14:35:53 UTC, Chris wrote:
> On Friday, 21 August 2015 at 12:59:09 UTC, John Colvin wrote:
>> On Friday, 21 August 2015 at 10:43:22 UTC, Chris wrote:
>>> On Thursday, 20 August 2015 at 15:57:47 UTC, John Colvin 
>>> wrote:
>>>> On Thursday, 20 August 2015 at 15:25:57 UTC, Chris wrote:
>>>>> Is there a way to flush a thread's message box other than 
>>>>> aborting the thread? MailBox is private:
>>>>>
>>>>> https://github.com/D-Programming-Language/phobos/blob/master/std/concurrency.d#L1778
>>>>
>>>> flush from inside the thread? You could call receiveTimeout 
>>>> with a 0 timer in a loop until it returns false.
>>>
>>> Yes, from inside the thread. I have a worker thread (with 
>>> receiveTimeout) that is started when the program starts and 
>>> sits there waiting for input. I naively thought this was a 
>>> great idea, until I noticed that when input comes fast the 
>>> mailbox grows and the bloody thread won't stop until all the 
>>> items in the mailbox are processed. I was looking for 
>>> something like `if (abort) { mailbox.flush(); }`
>>
>> void flushMailbox()
>> {
>>     bool r;
>>     do
>>     {
>>         r = receiveTimeout(Duration.zero, (Variant _){});
>>     } while(r);
>> }


Thanks by the way. This does the trick.


More information about the Digitalmars-d-learn mailing list