Article View: comp.unix.programmer
Article #3365g++ 3.0.3/libstdc++-v3 thread problem - help, please
From: Pedro Checo
Date: Fri, 10 May 2002 21:08
Date: Fri, 10 May 2002 21:08
81 lines
3947 bytes
3947 bytes
Hi. My program core dumps with a Bus Error. gdb points to a call to
realfree() in libc.so as the point of failure. The call in my code
which leads to this problem is this instantiation of ostrstream inside
of a while() loop:
ostrsream msg;
Below, I'm including a better listing of the code. The program has the
main thread plus another 2 threads. The above line is in the main
thread. The program ran for 3 hrs before it dumped.
My question is: am using the correct flags for multithreaded support?
Is anyone experiencing problems with iostream operations in a
multithreaded program?
These are the flags I'm using for compiling: -c -g -pthreads -Wall
-Wpointer-arith -O2 -fcheck-new -D_REENTRANT -D__STL_PTHREADS
-DBOOST_SMART_PTR_CONVERSION -DSMART_PTR_BH_ENHANCED
g++ -v is:
Configured with: ../configure --with-as=/usr/local/bin/as
--with-ld=/usr/local/bin/ld --enable-libgcj
Thread model: posix
gcc version 3.0.3 using libstdc++.so.3.0.2
My version of UNIX is Solaris 8:
SunOS sybdev2 5.8 Generic_108528-07 sun4u sparc SUNW,Ultra-60
Here is a listing of the lines around the problem:
while ( continueWorking() ) // returns true from 8am to 6pm
{
recvBuf[0] = '\x0';
if ( (byteCnt = receiverSock->recv(recvBuf, 1024 * 4, senderAddr))
>= 0 )
{
if ( byteCnt > 0 )
{
recvBuf[byteCnt] = '\x0';
// ... code locking a mutex and inserting recvBuf[]
// into a shared std::vector ...
ostrstream msg; <<<---- THIS IS WERE THE CORE ORIGINATES
msg << "Received " << byteCnt << " bytes from ";
msg << senderAddr.get_host_name();
msg << ":" << senderAddr.get_port_number();
msg << ". Data is: '" << recvBuf << "'";
logger->log(msg);
}
}
}
Here is the output from gdb when analyzing the core (Bus Error):
#0 0xff0c1ba0 in realfree () from /usr/lib/libc.so.1
#1 0xff0c23a4 in cleanfree () from /usr/lib/libc.so.1
#2 0xff0c14d8 in _malloc_unlocked () from /usr/lib/libc.so.1
#3 0xff0c13cc in malloc () from /usr/lib/libc.so.1
#4 0xff1e77c8 in _Znwj (sz=16)
at ../../../../libstdc++-v3/libsupc++/new_op.cc:47
#5 0xff1e794c in _Znaj (sz=16)
at ../../../../libstdc++-v3/libsupc++/new_opv.cc:36
#6 0xff1e47b8 in _ZNSt12strstreambuf8_M_allocEj (this=0xffbef464,
n=16)
at ../../../../libstdc++-v3/src/strstream.cc:316
#7 0xff1e36dc in _ZNSt12strstreambufC1Ei (this=0xffbef464,
initial_capacity=0)
at ../../../../libstdc++-v3/src/strstream.cc:69
#8 0xff1e533c in _ZNSt10ostrstreamC1Ev (__vtt_parm=0xffbef460)
at ../../../../libstdc++-v3/src/strstream.cc:383
#9 0x1b6d0 in _ZN16PosSummaryServer8receiverEv (this=0xffbef7b0)
at pss2.cpp:74
#10 0x1d22c in _ZN16PosSummaryServer4mainEiPPc (this=0xffbef7b0,
argc=223824,
argv=0xffbef708) at pss2.cpp:282
#11 0x1ab4c in main (argc=2, argv=0xffbef944) at pss.cpp:59
Technical Details
Message-ID:
<be381207.0205101308.223731ef@posting.google.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!postnews1.google.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10ba33,c2823dc2ed2ba6b6 X-Google-Attributes: gid10ba33,public X-Google-Thread: ffc1e,60c2dc3b8f48b012,start X-Google-Attributes: gidffc1e,public X-Google-Thread: fc89c,60c2dc3b8f48b012,start X-Google-Attributes: gidfc89c,public X-Google-ArrivalTime: 2002-05-10 14:08:18 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!postnews1.google.com!not-for-mail From: pedro@checo.net (Pedro Checo) Newsgroups: comp.unix.programmer,comp.programming.threads,gnu.g++.help Subject: g++ 3.0.3/libstdc++-v3 thread problem - help, please Date: 10 May 2002 14:08:17 -0700 Organization: http://groups.google.com/ Lines: 81 Message-ID: <be381207.0205101308.223731ef@posting.google.com> NNTP-Posting-Host: 209.83.183.40 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1021064898 31690 127.0.0.1 (10 May 2002 21:08:18 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 10 May 2002 21:08:18 GMT