Function pointer changing or overwritten?
Feb 14, 2011 at 3:25am UTC
1 2 3 4 5
void Receiver::start(){
running = true ;
std::cout << "updateThread " << (void *)updateThread << std::endl;
_beginthreadex(NULL, 0, &updateThread, this , 0, pThreadHandle);
}
Output:
Call stack for segmentation fault:
1 2 3 4 5 6 7 8 9
#0 7C8107C6 KERNEL32!CreateRemoteThread() (C:\WINDOWS\system32\kernel32.dll:??)
#1 00402B67 gps::DataManager::getMeasDataAtTime(this=0xffffffff, gpsTime=0, threshold=2.8900590577460985e-305, retData=@0x0) (C:\Documents and Settings\PC_XPlane\Desktop\WTF\Receiver.cpp:68)
#2 7C81084D KERNEL32!CreateThread() (C:\WINDOWS\system32\kernel32.dll:??)
#3 77C3A443 msvcrt!_beginthreadex() (C:\WINDOWS\system32\msvcrt.dll:??)
#4 00402C23 gps::Receiver::start(this=0xb44d90) (C:\Documents and Settings\PC_XPlane\Desktop\WTF\Receiver.cpp:109)
#5 004099CD gps::AttitudeSolver::init() (C:\Documents and Settings\PC_XPlane\Desktop\WTF\AttitudeSolver.cpp:125)
#6 0040F01B gps::AttitudeSolver::run() (C:\Documents and Settings\PC_XPlane\Desktop\WTF\AttitudeSolver.cpp:147)
#7 0040F059 main() (C:\Documents and Settings\PC_XPlane\Desktop\WTF\AttitudeSolver.cpp:783)
See the address of gps::DataManager::getMeasDataAtTime? It is the "same" as updateThread...
What is going on?
Nick.
Feb 14, 2011 at 9:45am UTC
We have no idea what type pThreadHandle is or what value you've assign to it or what updateThread does ...
Feb 14, 2011 at 10:47am UTC
Sorry:
1 2 3 4 5 6 7 8
uintptr_t _beginthreadex(
void *security,
unsigned stack_size,
unsigned ( *start_address )( void * ),
void *arglist,
unsigned initflag,
unsigned *thrdaddr
);
And updateThread does nothing (cout << "In here" << std::endl;). See I'm sure updateThread is meant to be called after "KERNEL32!CreateThread()" but as you can see getMeasDataAtTime() is called - which is completely random... hence why I pointed out the addresses. updateThread is a function defined in namespace gps, it is not a member function.
Anyway, I'll try recreate the problem in a small program.
Nick.
Feb 14, 2011 at 11:19am UTC
What compiler warning level are you compiling at? I'd expect a warning about passing the address of a function and about not casting
this
in:
_beginthreadex(NULL, 0, &updateThread, this , 0, pThreadHandle);
Anyway, as the debugger says, CreateThread is definitely calling gps::DataManager::getMeasDataAtTime.
I know the signature of system calls as those are well documented. I was hoping you'd post your code as that's likely where the error lies.
Topic archived. No new replies allowed.