Windows Threading & Exceptions

I have a couple threads running. Each thread is passed a pointer to an object - in fact it is one thread per object. The thread then loops - calling a public member function of the passed object each loop. The member function throws & catches an exception. Now, sometimes the program runs for a while, sometimes is breaks down straight away. Here is some of the debug info I have (error & call stack). Can anyone make anything of this?

Run 1: SIGILL

#0 00000000 0x0040e7c9 in __cxa_throw() (??:??)
#1 0040CEA4 GpsSensor::sense(this=0x3d3b40) (C:\Documents and Settings\PC_XPlane\Desktop\GPS Attitude Determination\GpsSensor.cpp:222)
#2 0040D46B sensorThread(param=0x3d3b40) (C:\Documents and Settings\PC_XPlane\Desktop\GPS Attitude Determination\GpsSensor.cpp:313)
#3 77C3A3B0 msvcrt!_endthreadex() (C:\WINDOWS\system32\msvcrt.dll:??)
#4 7C80B50B KERNEL32!GetModuleFileNameA() (C:\WINDOWS\system32\kernel32.dll:??)
#5 00000000 0x00000000 in ??() (??:??)

Run 2: SIGSEGV Error

#0 7C901095 ntdll!RtlEnumerateGenericTableLikeADirectory() (C:\WINDOWS\system32\ntdll.dll:??)
#1 00000000 0x0078ff30 in ??() (??:??)
#2 00000000 0x00482516 in std::__ostream_insert<char, std::char_traits<char> >() (??:??)
#3 00000000 0x00000018 in ??() (??:??)

Run 3: SIGSEGV Error

#0 00000000 0x003d0004 in ??() (??:??)
#1 00000000 0x0078fd40 in ??() (??:??)
#2 77C5FCA0 msvcrt!_iob() (C:\WINDOWS\system32\msvcrt.dll:??)
#3 00000000 0x00493540 in std::wclog() (??:??)
#4 00000000 0x0078fda3 in ??() (??:??)
#5 00000000 0x004930e4 in std::cout() (??:??)
#6 0042E6D0 std::__use_cache<std::__numpunct_cache<char> >::operator() () (??:??)

Run 4: SIGSEGV Error

#0 77C301C5 wsopen() (C:\WINDOWS\system32\msvcrt.dll:??)
#1 00000000 0x00000024 in ??() (??:??)
#2 00000000 0x00b8fed4 in ??() (??:??)
#3 00000000 0x00b8fe40 in ??() (??:??)
#4 00000000 0x004146c6 in __cxa_get_globals() (??:??)

And here is some code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

#include <process.h>
#include <windows.h>

class GpsSensor; //Creates the thread and passes 'this' as arg.

void GpsSensor::sense(){

    try{
        throw 1;
    }
    catch(const std::exception& e){
        std::cout << "Exception Thrown From Sense(): ";// << e.what() << std::endl;
    }
    catch(int arg){
        std::cout << "Caught Int Exception" << std::endl;
    }

    std::cout << "Finished sense() for Rec: " << getRecId() << std::endl;

}

unsigned __stdcall sensorThread(void * param){

    GpsSensor* sensor = static_cast<GpsSensor*>(param);

    while(sensor->isRunning()){

        std::cout << "About to sense for rec: " << sensor->getRecId() << std::endl;
        sensor->sense();
        std::cout << "Sensed for rec: " << sensor->getRecId() << std::endl;
    }

    return 1;

}


I don't have much experience with this kind of debugging. If you need any more information just tell me and I'll figure out how to get it. I'm currently just running the debugger in Codeblocks and pressing step-out until I get one of the error messages.

I have absolutely no idea what is going on here. Any help would be awesome!

Thanks.

Nick.

Last edited on
SIGSEGV is a segmentation fault/invalid memory reference error. Sounds like a problem with your
GpsSensor* sensor = static_cast<GpsSensor*>(param);
I'd add a check to make sure sensor isn't NULL before continuing

If you compile with the -g switch in gcc/g++ it leaves debugging information in so you can find out the line numbers of your program where it terminated.
I'm not sure which debugger CodeBlocks uses but if its similar to gdb you can use "print sensor" to tell you the value of sensor when the program crashed.



Where is sensorThread() called/started in your program?
Last edited on
Are you running under cygwin? Is it similar to this (which wasn't answered).
http://www.cygwin.com/ml/cygwin/2001-08/msg00191.html
Topic archived. No new replies allowed.