"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message
news:c25pm3h23opv0pupnbuokno534rmsadc7g@4ax.com...
I'd suggest learning how to use threads. It isn't that hard for the case
you want.
Good suggestion ...
I've got a small SDI test program coming together that has user-interface
threads. My current thinking is to use a series of registered
UWM_MyMessage_guid's to communicate to the threads ... (using
PostThreadMessage ??). When they are done with their subset of the search,
the main thread will be waiting on a WaitForMultipleObjects (or
MsgWaitForMultipleObjects ??) to "gather up" the results of the search.
Suppose the end-user has a quad-core. The main bottleneck task is to
search thru 31,102 lines finding which lines (actually verses) have
matches. I split up the search into groups of about 8000 verses. Since
they are all threads in the same process, they can access the parameters
of the search .... word(s) to find, case-sensitive-yes-no, regex-yes-no,
etc. Then "kick off" the search with:
m_thread_A->PostThreadMessage(BB_FIND_guid, firstVerse_A, lastVerse_A)
m_thread_B->PostThreadMessage(BB_FIND_guid, firstVerse_B, lastVerse_B)
m_thread_C->PostThreadMessage(BB_FIND_guid, firstVerse_C, lastVerse_C)
m_thread_D->PostThreadMessage(BB_FIND_guid, firstVerse_D, lastVerse_D)
When they are done, each thread could do one of the following:
::SetEvent(hDoneEvents[0]);
::SetEvent(hDoneEvents[1]);
::SetEvent(hDoneEvents[2]);
::SetEvent(hDoneEvents[3]);
The main thread is held up on:
::WaitForMultipleObjects(4, hDoneEvents, TRUE, INFINITE);
Or would the following be a feasible/better approach to "wrapping up" the
search?
Can the 4 searching threads do a "cascade" of UWM_DONE_guid messages?
Thread_A would indicate to Thread_B ... "I'm done". Thread_B would receive
this message when it was done with its 8000 verses, and its action in
response to getting that message would be to send a message to Thread_C
that "I'm done", Thread_C to Thread_D ... "I'm done", and then Thread_D to
the main thread ... "I'm done".
Is that how posted messages are handled? While a user thread is completely
busy with its core "pegged" doing the search, would it not get a message
posted to its queue ... until it was idle?
appear to be locked up. It may even produce a message from Windows like
GUI thread.
queue. The thread cannot know about it or process it until it returns to
the MFC message pump. There's no point in involving all four threads in a
cascade just to let the main thread know they're done. Every thread can
post a "I'm Done" message to a main thread window. Let the main thread
window figure out when it has heard from all four.