saintmike has asked for the wisdom of the Perl Monks concerning the following question:

If untie() figures out that there's still another reference to the value returned by tie(), it will print a untie attempted while 1 inner references still exist" warning.

But what if a new process gets spawned after the tie(), is there a way to avoid the warning? Like in

use strict; use warnings; use IPC::Shareable; my $scalar; my $foo = tie $scalar, 'IPC::Shareable', 'k123', { create => 1, destroy => 1 }; my $pid = fork(); if(! defined $pid) { die "fork err"; } elsif($pid == 0) { # Child undef $foo; untie $scalar; print "Child ends\n"; exit 0; } else { # Parent sleep(1); undef $foo; untie $scalar; print "Parent ends\n"; }
which prints
untie attempted while 1 inner references still exist at ./test.pl line 17.
Child ends
untie attempted while 1 inner references still exist at test.pl line 24.
Parent ends
Sure, no warnings would suppress the warning. Other options (besides calling tie() after the fork())?

Replies are listed 'Best First'.
Re: Unavoidable "untie attempted while inner references" with fork()?
by ysth (Canon) on Jul 18, 2006 at 23:45 UTC
    If your tie class provides an UNTIE method (even an empty one), the warning is bypassed under the theory that you know what you are doing.

    But the extra reference seems to be just a bug in IPC::Shareable; it happens even without the fork.

    Update: bug may be too strong a word; you could do $foo->remove() in the child before the untie.

      Yeah, nice find, this solution falls into the 'suppress warning' category:
      ... package IPC::Shareable; sub UNTIE {}; package main; ...