Re: Multi Threading Options



Mark Randall wrote:
My problem is that I want to run a pretty hefty drawing routine on the other thread - I really want to cause thread 2 to wait for data to finish being written before it starts drawing the next image, and cause thread 2 to tell thread one it can update again once it has finished drawing.

In code such as this, where the threads are to "voluntarily" take turns, you have a third option. In addition to a mutex or crictical section, you can consider the use of an interthread message. When thread 1 finishes updating the list it can post a message to thread 2 requesting a paint. And vice versa. Use PostMessage to a GUI thread, PostThreadMessage to a non-GUI thread. Example here:
http://www.mvps.org/vcfaq/mfc/index.htm


--
Scott McPhillips [VC++ MVP]

.


Loading