Re: Minimum VC++ for Multi-Core?
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Thu, 24 May 2007 01:05:07 -0400
You have some serious synchronization bug somewhere. The symptoms you describe are
characteristic of race conditions that will show up on multiprocessors, where threads can
start immediately, vs. uniprocessors, where there are delays in starting threads.
As I pointed out in my article, kb192570 is horrible in its structure; it gets threading
wrong, synchronization wrong, interthread communication wrong, and sockets wrong, so using
it as a basis is quite likely to result in complete catastrophe. I would be DEEPLY
suspect of ANY code based on that example that was anything other than a total rewrite
that threw away nearly all of the original code, all of the synchronization of the
original code, all of the interthread communication of the original code, and all of the
socket handling code of the original code. If it ever worked, it was akin to a miracle. I
don't think it ever worked correctly. It would not surprise me in the slightest that any
program based on it would crash immediately on a multiprocessor; what was amazing was that
nothing ever crashed on a uniprocessor.
In order to get something that was remotely production quality, I essentially had to
discard all of the code and rewrite it.
See my essay on this topic on my MVP Tips site.
joe
On Wed, 23 May 2007 13:19:04 -0600, "Tom Salicos" <TSalicos@xxxxxxxxxxxx> wrote:
The example program mentioned (kb/192570) runs fine in Dual Core mode. AboutJoseph M. Newcomer [MVP]
two years ago I stripped the example down to bare bones, then built it back
up to fit my needs.
My program "crashes" immediately and the error is this:
"This application has requested the Runtime to terminate it in an unusual
way".
It's an MFC dialog-based application. Service Pk is 6
On a development system with Dual Core enabled, the error does *not* occur
in Debug.
Occasionally it does not occur in Release mode either. Also, started from
the DeskTop it may not always occur.
When the error occurs in Release Mode the call stack window shows the
following;
KERNEL32! 7c812a5b()
MSVCRT! 77c2272c()
MFC42! 73e309c1()
MFC42! 73ddbaf0()
MFC42! 73de9562()
MFC42! 73de5f14()
MFC42! 73de0bc7()
MSVCRT! 77c3a3b0()
KERNEL32! 7c80b683()
My program starts from zero to ten client threads to pull data from our
control systems.
The program does not crash if only one connection is enabled.
A loop starts the threads by calling my DoConnect(). I wound up putting a
Beep() in that loop as a troubleshooting tool. With the beep, no more
crash. I cut the Beep() down to 10ms and no more crash. Remove the Beep()
and it crashes.
If I start the app with all connections disabled then enable them one at at
time, there is no crash.
It seems like the delay from the Beep() a helpful delay but I don't know
why.
In my app CClientThread is derived from CWinThread and has the member
m_Socket which is derived from CAsyncSocket. DoConnect() starts a new
thread each time it's called.
I have proven that the crash occurs before the loop that calls DoConnect()
completes. It happens whether any connection is made or not. So no
OnConnect or OnReceive has ever occured and the app has not tried to use the
connection.
This is the gist of the code:
void StartAllThreads()
{
for(int i=0; i < nNumConnections; ++i)
{
DoConnect(Name of PC, etc );
}
AfxMessageBox("Hi ") // (debugging) The crash occurs before this point.
}
bool CAsyncClientDlg::DoConnect(
{
// Start the client thread suspended
CClientThread* pThread =
(CClientThread*)AfxBeginThread(RUNTIME_CLASS(CClientThread),
THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED);
if (pThread == NULL)
{
// error message
return FALSE;
}
// Set a few variables via pThread->
//
// Let thread run
pThread->ResumeThread();
return TRUE;
}
Again, problem does not occur if I put a delay between thread starts. But I
hate to do that without knowing what is actually causing the error.
Ideas ???
Thanks,
Tom
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- References:
- Minimum VC++ for Multi-Core?
- From: Tom Salicos
- Re: Minimum VC++ for Multi-Core?
- From: Tom Salicos
- Minimum VC++ for Multi-Core?
- Prev by Date: Re: Seeing VERSIONINFO under Vista?
- Next by Date: Altert boxes in MFC
- Previous by thread: Re: Minimum VC++ for Multi-Core?
- Next by thread: How to change the taskbar grouping icon ??
- Index(es):
Relevant Pages
|