in reply to Attempt to free non-existent shared string 'io_socket_type', Perl interpreter: 0x84972e0 during global destruction.

I recognize those as being from IO::Socket. Presumably, IO::Sockets objects can't be shared. Create your connection in the thread where you use it. Your current model doesn't make much sense anyway. Why would you do the slow operation of connecting outside of the thread only to pass the object to the thread?

sub method { my ($self, $deviceInfo, $count) = @_; my $machine = Connector->new($deviceInfo); while ($count) { my ($status, $hostname) = $self->cmd("hostname"); print "$count: $hostname\n"; sleep 1; --$count; } } my $thr1 = threads->create( 'method', $deviceInfo1, 10 ); my $thr2 = threads->create( 'method', $deviceInfo2, 6 );

Net-SSH2 is a threadsafe module, as far as I know.

What gives you that idea? That's a dangerous assumption to make, especially where XS code and external libraries are concerned.

  • Comment on Re: Attempt to free non-existent shared string 'io_socket_type', Perl interpreter: 0x84972e0 during global destruction.
  • Download Code

Replies are listed 'Best First'.
Re^2: Attempt to free non-existent shared string 'io_socket_type', Perl interpreter: 0x84972e0 during global destruction.
by madhurikl (Novice) on Dec 14, 2009 at 09:32 UTC

    Thanks for this solution ikegami. But, I need to call different methods doing different long operations simultaneously. For example, keep writing data in one method, and keep checking the CPU load from the other method. Both these methods should be called on the same remote machine, ie. on the same object. Can there be a solution for having the object creation outside the thread?

      The problem arises because the destructor for the shared object is being called from each thread that has a copy of it.

      One way to avoid that is to add your own destructor method and defer destruction until the called by the last thread that has a copy.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        Thanks BrowserUk.

        How to defer destruction until the last thread has a copy?

        How do we defer destruction until the last thread has a copy?