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

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?

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

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

    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?

        Patience is a virtue.

        With problems of this nature you'd get a more (and faster) responses if you posted a runnable example. As is, you force anyone thinking of trying to help, to have to try to recreate the code that you already have sitting on your harddrive. Most won't bother. I tried and failed.

        WIAT: Modifying your OP without attribution, such that it makes my initial response read as wrong, is not the best way to endear yourself.


        I cannot find the discussion I remember concerning DESTROY methods and threads, despite several searches. However, it may not be applicable as I have a feeling that half-remembered discussion was XS related.

        However, two possibilities come to mind:

        • Avoid closures by reformatting your code thus:
          use sshConnector; sub methodA { my $self = shift; my $count = shift; my $hostname; while ($count) { ($status,$hostname) = $self->cmd("hostname"); print "$count : $hostname\n"; sleep 1; $count--; } } sub methodB { my $self = shift; my $count = shift; my $hostname; while ($count) { ($status,$hostname) = $self->cmd("hostname"); print "$count : $hostname\n"; sleep 2; $count--; } } my $machine1 = new Connector($deviceInfo1); my $thr1 = threads->create('methodA',$machine1,10); my $machine2 = new Connector($deviceInfo2); my $thr2 = threads->create('methodB',$machine2,6); $thr1->join(); print "First thread over\n"; $thr2->join(); print "Second thread over\n";

          Closures and threads have a history of bugs--many fixed--but still best avoided if possible.

        • Try marking your objects shared explicitly:
          my $machine1 :shared = new Connector($deviceInfo1); my $thr1 = threads->create('methodA',$machine1,10); my $machine2 :shared = new Connector($deviceInfo2); my $thr2 = threads->create('methodB',$machine2,6);

          On the off-chance that the relatively recent changes that made it possible to shared blessed references also added some magic to ensure the appropriate ordering of destructors.


        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.