Click to See Complete Forum and Search --> : Debugging a multithreaded DLL with STL


Pinky98
February 6th, 2003, 12:37 AM
(Also, submitted in VC++ forum)

Hi everyone,

I am debuggin an C++ app and am having some trouble with it.

It is a multithreaded DLL, which makes use of the STL library. The program dies in apparently random places. Every time it fails the operating system reports an error



Runtime Error!

Program: ...\C++_Caller_App\Caller.exe


abnormal program termination


Caller.exe is the calling application which calls my DLL. I have managed to identify that the problem is DEFINITELY in the DLL not the calling app, and have (to some degree) managed to isolate the portion of code giving the error. (Which is not easy because it seems to occur in different places, at different times)

This error only occurs when I have complied the DLL in RELEASE configuration, never in DEBUG... which would usually make me think there was a memory leak from pointers or out-of-bounds arrays, but I am not using any of these. The only thing which I am using in that section of code is the STL "string" class. (I'm using STL version 3.3 for Silicon Graphics)

Does any one have any idea what could be causing the error? And/Or how to fix it?

P.S. I have finished writting the program and it is not small at all, so I can not afford to re-write it to use, say, MFC::CString (YUCK!!)

Thanks

DanM
February 6th, 2003, 01:55 AM
First, we would like to see some code.
Second, did you apply all the pathches to the STL library (you can look at http://www.dinkumware.com/vc_fixes.html for more details) ? The string class is pretty buggy - reference counting doesn't work properly for mutithreaded apps.
You can build a release version with symbols and try to use something like the old MSJExceptionHandler to get more information about the place the crash occurs:
http://www.microsoft.com/msj/defaultframe.asp?page=/msj/0497/hood/hood0497.htm&nav=/msj/0497/newnav.htm

Dan

kuphryn
February 6th, 2003, 01:37 PM
Are there functions that return references to string objects. One solution is return the string by value.

Kuphryn

DanM
February 6th, 2003, 03:25 PM
And why would this approach help ?

Dan

shridharng
February 6th, 2003, 05:49 PM
I had that problem when the library i am linking to is built with different code generation option. (when the library is built using debug multi threaded and my application is built using single threaded library).

Paul McKenzie
February 6th, 2003, 06:08 PM
Originally posted by Pinky98
(Also, submitted in VC++ forum)

The only thing which I am using in that section of code is the STL "string" class. (I'm using STL version 3.3 for Silicon Graphics)
This is confusing. VC++ comes with a string class from DinkumWare. What reasons made you use SGI's? And when you are using SGI's, how do you make sure you've totally "turned off" the VC++ string class so that you don't get conflicts with two different string classes running around? (I'm not saying it isn't possible -- I want to know just what steps you did to make sure this isn't happening)

If you try to mix and match string classes, I can see where there would be random errors, especially if you try to pass any of these string objects to other functions. One function is built assuming std::string from Dinkumware, and you pass it a std::string from SGI. A crash is inevitable.

Another thing, std::string is not guaranteed to be thread safe. If you use SGI, you are probably not using a thread-safe library.

Regards,

Paul McKenzie

mwilliamson
February 6th, 2003, 06:45 PM
I find you get abnormal program termination when you throw an exception from a destructor.