This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Problem with Global Objects/Classes and Libraries
- To: gcc-bugs at gcc dot gnu dot org
- Subject: Problem with Global Objects/Classes and Libraries
- From: "Marshall H Hamilton" <Marshall dot Hamilton at fisc dot com>
- Date: Thu, 22 Mar 2001 14:50:00 -0500
I'm having a problem with Global Objects/Classes in a Unix library, and I'm
wondering if it's a bug with the GNU compiler.
Here's the situation: I'm building a library on Unix using g++, and in one of
the *.cpp files that are used to build the library I declare a global
object/class. (Note: I'm multi-threading this application).
At the top of the *.cpp file I have the following statement:
CRay crThdInfoList;
This declares a global variable of type CRay (which is a class I have defined
elsewhere).
Whenever I attempt to access the class/object from the main thread, or any
other thread, I get a core dump.
For example, in a procedure in the *.cpp file I have the following statement:
stat = crThdInfoList.Add((ULONG)pThdInfo);
This statement will generate a core dump. If I comment it out, and try
something similar in any thread, I get a core dump. Also note, that I lock a
mutex before I execute this statement, and I unlock the mutex immediately
after the statement, but a core dump is still generated. Using the mutex
should handle serializing access to the global object.
I'm wondering if this is a problem with the GNU compiler because I'm actually
porting this code from Windows NT/Visual C++, and it works fine over there.
Is there a problem with accessing global objects from threads in GNU g++? As
an experiment, I've tried similar things with other types of global variables
such as int, and they work fine. However, it has definitely been crashing for
me on global objects/classes.
Any ideas?