Bug#718438: Shared references (threads::shared) disappear on sub return in perl

Alexey Borzenkov snaury at gmail.com
Wed Jul 31 18:56:07 UTC 2013


Package: perl
Version: 5.14.2

When using threads::shared on Perl 5.14 using many kinds of
expressions in sub's return becomes very dangerous, as return values
just become undef undef certain circumstances. For example this
program would die in Perl 5.14, but would work normally in Perl 5.12
or Perl 5.16:

    use strict;
    use threads ();
    use threads::shared;

    sub test_clone {
        my $ref = shared_clone([{a => 1, b => 2}]);
        return $ref->[0];
    }

    die "not defined" unless defined(test_clone);

This causes threaded perl programs on Debian 7.0 to produce really
weird failures. I have tried filing this bug upstream (see
https://rt.perl.org/rt3/Ticket/Display.html?id=119089 for reference),
however the upstream reply was this bug was already fixed in 5.15.7
with commit 6f48390ab209d16ee8f795f0a83677c8bd9ac69c, and that it
wouldn't be backported since perl 5.14 is out of its maintenance
period. This means this bug can only be fixed in Debian wheezy, since
Perl 5.14 is currently shipped even in both stable and unstable.

I know about the workaround of temporarily assigning result to a
variable before returning, and use where possible, however that is
error-prone, you have to know that a sub may fail like that to apply
the workaround and meanwhile threaded perl applications that use
queues are time-bombs since upgrading servers to Debian wheezy.




More information about the Perl-maintainers mailing list