Google Answers Logo
View Question
 
Q: Seeing bizarre CreateThread() behavior sometimes ( No Answer,   0 Comments )
Question  
Subject: Seeing bizarre CreateThread() behavior sometimes
Category: Computers > Programming
Asked by: dbright-ga
List Price: $20.00
Posted: 14 Jul 2002 06:07 PDT
Expires: 16 Jul 2002 11:11 PDT
Question ID: 39446
Hello,

I have a situation where I call CreateThread() and it succeeds, but the
thread does not start at the function address I specify.  It happens
often, but not always.  The call looks like this:

    m_hEventMonitorThread = CreateThread( 
        NULL,                        // no security attributes 
        0,                           // use default stack size  
        EventMonitor,                // thread function 
        (LPVOID)this,		// argument to thread function 
        0,                           // use default creation flags 
        &dwThreadId);                // returns the thread identifier

where EventMonitor is the function I wish the thread to begin
executing.


This code is actually part of a library I developed some time ago and
it always worked perfectly until now.  Previous projects that use this
library still work -- it just seems that new projects are having
problems.

Do you know of any reasons that a thread might begin executing at
0x00000000 when I specify otherwise?  This running on Win2000.

Thanks.

Request for Question Clarification by jeanluis-ga on 14 Jul 2002 09:01 PDT
When it used to work all the time, were you on Win2k, and were you
using the same compiler/libraries? Or did any of that stuff change?
Also are you checking EventMonitor to see if it is a null pointer
before you use it?

This type of stuff if very hard to figure out remotely, some things
that come to mind however are, stack overflow issues, it could be the
case that you don't have enough stack, and for example, when you call
the function that calls CreateThread() the EventMonitor pointer is
getting corrputed. You can tell if this is the case by putting a watch
on EventMonitor and single stepping the function that calls
CreateThread() and if EventMonitor changes when it shouldn't then you
should goto the project settings and increase the stack reserve size.

That may not fix the problem, it is just a thought...

Clarification of Question by dbright-ga on 15 Jul 2002 08:24 PDT
I am seeing this problem on the same Win2k machine that I've always
used (also the machine the library was developed on).  I have checked
the EventMonitor function pointer before CreateThread() is called and
it has a legitimate value.

I'll give changing the stack reserve size a try, but I agree that it
seems like a longshot.  Thanks for your interest.

Clarification of Question by dbright-ga on 15 Jul 2002 08:34 PDT
Also, as far as project libraries/setting changine, etc.:  I don't
BELIEVE anything has changed, but it really seems to be the only
possible variable with this problem.  I have tried creating multiple
projects, using the same settings and libraries as the projects that
work but haven't had any luck.

I'm not sure what could possibly change that would cause
CreateThread() to work only occasionally, though.
Answer  
There is no answer at this time.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy