Seg fault with libstdc++-v3 and pthreads
Moore, David
David.Moore@Dialogic.com
Sat Apr 1 00:00:00 GMT 2000
Hi,
I found your post (below) on the libstdc++-v3 mailing list archive. I was
also trying to use the libstdc++-v3 with pthreads, with the same result.
I would greatly appreciate knowing - were you able to find a way around this
problem, or is there no solution at this stage of the libstdc++ development?
Thanks,
David Moore.
---------------------------------------------------------------------------
Tue, 23 Nov 1999
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
More information about the Libstdc++
mailing list