Good Coding? (Multiple Message Loops) Good Coding? (Multiple Message Loops) multithreading multithreading

Good Coding? (Multiple Message Loops)


Using message loops in each thread is perfectly fine; Windows is optimized for this scenario. You are right to avoid polling, but you may want to look into other event-based designs that are more efficient still, for example preparing a package for transfer and calling SetEvent to notify a thread it's ready, or semaphore and thread-safe queue as Martin James suggests.


I'm not 100% sure what you are doing here but, with a bit of 'filling in' it doesn't sound bad:)

When your app is idle, (no comms), is CPU use 0%?

Is your app free of sleep(0)/sleep(1), or similar, polling loops?

Does it operate with a reasonably low latency?

If the answers are three 'YES', you should be fine :)

There are a few, (very few!), cases where polling for results etc. is a good idea, (eg. when the frequency of events in the threads is so high that signaling every progress event to the GUI would overwhelm it), but mostly, it's just poor design.