digitalmars.D.learn - flush MessageBox
- Chris (3/3) Aug 20 2015 Is there a way to flush a thread's message box other than
- John Colvin (3/6) Aug 20 2015 flush from inside the thread? You could call receiveTimeout with
- Chris (8/15) Aug 21 2015 Yes, from inside the thread. I have a worker thread (with
- John Colvin (13/29) Aug 21 2015 void flushMailbox()
- Chris (11/41) Aug 21 2015 Wouldn't it be easier to have a library function that can empty
- Chris (2/31) Aug 21 2015 Thanks by the way. This does the trick.
- John Colvin (3/15) Aug 21 2015 yes, it would be better. Please file an enhancement request:
- Chris (3/22) Aug 24 2015 Done.
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
Aug 20 2015
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#L1778flush from inside the thread? You could call receiveTimeout with a 0 timer in a loop until it returns false.
Aug 20 2015
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: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(); }`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#L1778flush from inside the thread? You could call receiveTimeout with a 0 timer in a loop until it returns false.
Aug 21 2015
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:void flushMailbox() { bool r; do { r = receiveTimeout(Duration.zero, (Variant _){}); } while(r); } You could optimise that to more efficiently deal with the actual types you're receiving, instead of making a Variant every time, but it's probably not worth it. The compiler might even optimise it away anyway.On Thursday, 20 August 2015 at 15:25:57 UTC, Chris wrote: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(); }`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#L1778flush from inside the thread? You could call receiveTimeout with a 0 timer in a loop until it returns false.
Aug 21 2015
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:Wouldn't it be easier to have a library function that can empty the mailbox immediately? It's a waste of time to have all items in the mailbox crash against a wall, before you can go on as in [ item1 // cancel item2 ===> do nothing return; item3 ===> do nothing return; ] In parts I find std.concurrency lacking. Simple things sometimes need workarounds.On Thursday, 20 August 2015 at 15:57:47 UTC, John Colvin wrote:void flushMailbox() { bool r; do { r = receiveTimeout(Duration.zero, (Variant _){}); } while(r); } You could optimise that to more efficiently deal with the actual types you're receiving, instead of making a Variant every time, but it's probably not worth it. The compiler might even optimise it away anyway.On Thursday, 20 August 2015 at 15:25:57 UTC, Chris wrote: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(); }`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#L1778flush from inside the thread? You could call receiveTimeout with a 0 timer in a loop until it returns false.
Aug 21 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:Thanks by the way. This does the trick.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:void flushMailbox() { bool r; do { r = receiveTimeout(Duration.zero, (Variant _){}); } while(r); }On Thursday, 20 August 2015 at 15:25:57 UTC, Chris wrote: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(); }`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#L1778flush from inside the thread? You could call receiveTimeout with a 0 timer in a loop until it returns false.
Aug 21 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:yes, it would be better. Please file an enhancement request: https://issues.dlang.org[...]Wouldn't it be easier to have a library function that can empty the mailbox immediately? It's a waste of time to have all items in the mailbox crash against a wall, before you can go on as in [ item1 // cancel item2 ===> do nothing return; item3 ===> do nothing return; ] In parts I find std.concurrency lacking. Simple things sometimes need workarounds.
Aug 21 2015
On Friday, 21 August 2015 at 17:05:56 UTC, John Colvin wrote:On Friday, 21 August 2015 at 14:35:53 UTC, Chris wrote:Done. https://issues.dlang.org/show_bug.cgi?id=14953On Friday, 21 August 2015 at 12:59:09 UTC, John Colvin wrote:yes, it would be better. Please file an enhancement request: https://issues.dlang.org[...]Wouldn't it be easier to have a library function that can empty the mailbox immediately? It's a waste of time to have all items in the mailbox crash against a wall, before you can go on as in [ item1 // cancel item2 ===> do nothing return; item3 ===> do nothing return; ] In parts I find std.concurrency lacking. Simple things sometimes need workarounds.
Aug 24 2015