[Chicago-talk] Getting a thread to end

Jay Strauss me at heyjay.com
Sun Sep 12 09:44:58 CDT 2004


Hi,

I'm getting:
 A thread exited while 2 threads were running.

I've got a setup like:

run.pl
 uses security
 my $security = security->new()
  uses brokerage
   uses tws 
    use reader (which starts a new thread)
    
I get the message when run.pl ends.  

While I understand the meaning of the message, I'm not sure how
to get around it.  I have a DESTROY method in "tws" that isn't
getting called.  Inside "tws": 

sub DESTROY {
    my $self = shift;
    $self->disconnect if $self->connected;
};

sub disconnect {
    my ($self) = @_;

    return unless $self->connected;
    $self->reader->stop;
    $self->socket->close; 

    $self->connected(0);
}

Then inside of "reader" I've got:

sub stop {
    my $self = shift;
    ${$self->_run} = 0;
    my $t = $self->_thread;
    $t->join;
}

What I'd like to happen is when "run.pl" ends or is CTRL-C'd I'd like
the $tws->disconnect to be called so that things get wrapped up
correctly.

Thanks
Jay






More information about the Chicago-talk mailing list