bug-commoncpp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: TCPSession segfaults / hangs


From: David Sugar
Subject: Re: TCPSession segfaults / hangs
Date: Fri, 19 Nov 2004 15:30:22 -0500
User-agent: Mozilla Thunderbird 0.9 (Macintosh/20041103)

In 1.2.x, you must use detach rather than start if you intend for your thread to be a self deleting object, and you must exit the thread, and NOT put a delete this in it's final; a detached thread, that is, started by "detach" rather than "start", is automatically deleted when it exits now.

Rami Saarinen wrote:
I posted this message to the sourceforge forum, but it seems to be very
quiet so I decided to post to this mailinlist too. Sorry for the
replication:

I have a small project in which I use commoncpp2 mainly for threading and
network stuff. In the project there is a TCPListener (a thread) that waits
for a new connection. It creates a TCPSessionThread for each new
connection. TCPSessionThread is basically a wrapper class around
TCPSession and contains mainly stuff like a pointer to object for callback
purposes. TCPListener looks like this (mostly copied from the examples): ... void run() { try { TCPSessionThread<T> *tcp; while(enabled) { while(soc->isPendingConnection()) { tcp = new TCPSessionThread<T>(*soc,this->master); tcp->detach(); //tcp->start(); } } } catch(Socket *socket) { ... And TCPSessionThread is just as simple.. could do some work on the buffer & data handling :) : ... void run() { ssize_t val=1; char buf[512]; string *ret=new string(); while(val>0) { val=readData((void *)buf,512); string s(buf,val); ret->append(s); if(ret->size()>MAX_IN_BYTECOUNT) throw OwnException("Buffer overrun in TCPSessionThread"); } ((T)this->master)->handleMessage(ret); } void final() { delete this; } ... The program works just fine on my desktop computer that has Fedora core 2 (and gcc 3.3.3) and commoncpp2 1.0.9 installed. It also works fine on windows 2000 (with ccpp2 1.0.13 IIRC). And on one old laptop with FC2 and ccpp2 1.1.0 except that now it prints Free() Invalid pointer error messages quite a lot. But on another laptop, where I need to get it to work, it does not work at
all. The setup is Fedora core 3 (gcc 3.4.2) and any version on ccpp2 (from
1.0.13 to 1.2.6). The problem seems to be TCPSession and especially the final() method of it. 1. If I use older version of ccpp2, I get free() invalid pointer error
from glibc and the program aborts. If I comment out the delete this line
from final method. The program seg-faults (IIRC) 2. If I use ccpp2 1.2.6 I get the same free() invalid pointer error, but
if I comment out the "delete this" from the final method the TCPListener
seems to hang for minutes after the first TCPSession is created. After
several minutes the program continues and finally handles the pending
connections. I do use mutexes quite a lot, but they should not be the cause of the lock-up/stall as the program works fine on other systems. Any ideas? I am about to remove the FC3 installation and install FC2 (on
Sunday) as I really need to get it working on the laptop, but it is a pain
to reinstall all the needed stuff again. So I'd be very very happy if
someone can tell me how to bypass this problem.
Oh, BTW, does one need to start() a thread after detach() as the detach()
par on the reference manual says "This is an alternative start() method
that resolves some issues with later glibc implimentations which
incorrectly impliment self-detach", but on W2K if I comment out the start,
nothing much happens. Thanks!




reply via email to

[Prev in Thread] Current Thread [Next in Thread]