Thread View: comp.unix.programmer
2 messages
2 total messages
Started by Pedro Checo
Fri, 10 May 2002 21:08
g++ 3.0.3/libstdc++-v3 thread problem - help, please
Author: 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
Re: g++ 3.0.3/libstdc++-v3 thread problem - help, please
Author: André Pönitz
Date: Mon, 13 May 2002 09:39
Date: Mon, 13 May 2002 09:39
18 lines
1851 bytes
1851 bytes
In gnu.g++.help Pedro Checo <pedro@checo.net> wrote: > 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; May I suggest to use 'ostringstream' (from <sstream>) instead of 'ostrstream' from <sstream>. Although both are coveres by the Standard the former is usually much easier to handle memory-wise. Your code won't change much in any case... Andre' -- Those who desire to give up Freedom in order to gain Security, will not have, nor do they deserve, either one. (T. Jefferson)
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads