This is the mail archive of the
libstdc++@sourceware.cygnus.com
mailing list for the libstdc++ project.
Seg-fault before main() with pthread
- To: libstdc++ at sourceware dot cygnus dot com
- Subject: Seg-fault before main() with pthread
- From: Gerwin Pfab <pb at schenk dot isar dot de>
- Date: Tue, 23 Nov 1999 10:01:08 +0100 (MET)
Greetings!
I know that stdlibc++ is not thread safe at the moment, but does this
implie the following behaviour?
The following code crashes in the initialization phase with Segmentation
fault. Without libstdc++ the program runs correct and returns 42.
Environment: stdlibc++ (CVS1999-11-19), gcc2.95.2, Linux 2.2.10:
--Code------------------------------------
#include <iostream>
#include <pthread.h>
struct foo {
pthread_mutex_t lock;
foo(){ pthread_mutex_init(&lock, 0); };
int bar(void);
};
int foo::bar(void)
{
pthread_mutex_lock(&lock);
// do something that should be locked
pthread_mutex_unlock(&lock);
return 42;
}
int main()
{
foo a;
cout << a.bar() << endl;
}
--Code end------------------------------------
It was compiled this way:
g++ -c -pipe -Wall -g -pthread -I../../lib -I/opt/libstdc++/include/g++-v3
-o test.o test.cc
g++ -pthread -static -o test test.o -L/opt/libstdc++/lib
and this is the gdb backtrace:
Program received signal SIGSEGV, Segmentation fault.
__pthread_mutex_init (mutex=0x0, mutex_attr=0xbffff744) at mutex.c:29
29 mutex.c: No such file or directory.
Current language: auto; currently c
(gdb) bt
#0 __pthread_mutex_init (mutex=0x0, mutex_attr=0xbffff744) at mutex.c:29
#1 0x808dc84 in _IO_init (fp=0x80fcf28, flags=0) at genops.c:556
#2 0x806c06f in __basic_file::__basic_file (this=0x80fcf28)
at ../../libstdc++/src/basic_file.cc:41
#3 0x805c99f in basic_filebuf<char, char_traits<char> >::_M_init_filebuf
(
this=0x80fa9e0) at ../../libstdc++/bits/fstream.tcc:48
#4 0x805cad6 in basic_filebuf<char, char_traits<char> >::basic_filebuf (
this=0x80fa9e0) at ../../libstdc++/bits/fstream.tcc:61
#5 0x80496da in __static_initialization_and_destruction_0
(__initialize_p=1,
__priority=65535) at ../../libstdc++/src/stdstreams.cc:35
#6 0x804987d in global constructors keyed to __cfileinit ()
at ../../libstdc++/bits/std_istream.h:70
#7 0x80b95d9 in __do_global_ctors_aux () at cp/tinfo.h:50
#8 0x80480ea in _init ()
#9 0x8079007 in __libc_start_main (main=0x8048200 <main>, argc=1,
argv=0xbffff894, init=0x80480c0 <_init>, fini=0x80c9920 <_fini>,
rtld_fini=0, stack_end=0xbffff88c) at
../sysdeps/generic/libc-start.c:83
(gdb)
Any idea what's going wrong here?
Thanks in advance
Gerwin
Gerwin Pfab <pb@schenk.isar.de> Dr. Schenk Industriemesstechnik GmbH
Dipl. Ing. Einsteinstrasse 37
Software Engineering D-82152 Martinsried
Tel: +49-89-85695-0
Fax: +49-89-85695-200