[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]

[perl #37671] Problem using "local" with "threads::shared"



# New Ticket Created by  dean@cs.serenevy.net 
# Please include the string:  [perl #37671]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/rt3/Ticket/Display.html?id=37671 >



This is a bug report for perl from dean@cs.serenevy.net,
generated with the help of perlbug 1.35 running under perl v5.8.4.


-----------------------------------------------------------------
Localizing variables bound to shared variables can cause the shared
variable to become undefined. The below is a test script which
produces the following output on my machine (tests 9,10 and 19,20
fail):


1..32
Scalars leaked: 1
ok 1 - direct passing (local $_): defined
ok 2 - direct passing (local $_): maintained value
Scalars leaked: 1
ok 3 - direct passing (local $g): defined
ok 4 - direct passing (local $g): maintained value
Scalars leaked: 1
ok 5 - direct passing (my $g): defined
ok 6 - direct passing (my $g): maintained value
Scalars leaked: 1
ok 7 - direct passing (my $x): defined
ok 8 - direct passing (my $x): maintained value
Scalars leaked: 1
not ok 9 - map (local $_): defined
# Failed test at line 42
not ok 10 - map (local $_): maintained value
# Failed test at line 43
Scalars leaked: 1
ok 11 - map (local $g): defined
ok 12 - map (local $g): maintained value
Scalars leaked: 1
ok 13 - map (my $g): defined
ok 14 - map (my $g): maintained value
Scalars leaked: 1
ok 15 - map (my $x): defined
ok 16 - map (my $x): maintained value
ok 17 - for $g (local $_): defined
ok 18 - for $g (local $_): maintained value
not ok 19 - for $g (local $g): defined
# Failed test at line 42
not ok 20 - for $g (local $g): maintained value
# Failed test at line 43
ok 21 - for $g (my $g): defined
ok 22 - for $g (my $g): maintained value
ok 23 - for $g (my $x): defined
ok 24 - for $g (my $x): maintained value
ok 25 - for copy of $g (local $_): defined
ok 26 - for copy of $g (local $_): maintained value
ok 27 - for copy of $g (local $g): defined
ok 28 - for copy of $g (local $g): maintained value
ok 29 - for copy of $g (my $g): defined
ok 30 - for copy of $g (my $g): maintained value
ok 31 - for copy of $g (my $x): defined
ok 32 - for copy of $g (my $x): maintained value




#### BEGIN test script: threads_and_local.t
#!perl -w

# Tests localization in threaded situations
#   (localization has been known to cause shared values to become undefined)

use strict;
use Config;

BEGIN {
    if (!$Config{useithreads}) {
        print "1..0 # Skip: no ithreads\n";
        exit;
    }
    if ($ENV{PERL_CORE_MINITEST}) {
        print "1..0 # Skip: no dynamic loading on miniperl, no threads\n";
        exit 0;
    }
    use threads;
    use threads::shared;
    print "1..32\n";
}

my $value :shared;
our $g;

my $test = 1;
sub ok {
    my ($ok, $name) = @_;

    # You have to do it this way or VMS will get confused.
    print $ok ? "ok $test - $name\n" : "not ok $test - $name\n";

    printf "# Failed test at line %d\n", (caller)[2] unless $ok;
    $test++;
    return $ok;
}

sub test_it {
  my ($sub, $message) = @_;
  $value = "foo";
  threads->create($sub, $value)->join;
  ok( defined($value), "$message: defined" );
  ok( ($value and $value eq 'foo'), "$message: maintained value" );
}

test_it sub { local__($_[0]) },              'direct passing (local $_)';
test_it sub { local_g($_[0]) },              'direct passing (local $g)';
test_it sub { my_g($_[0]) },                 'direct passing (my $g)';
test_it sub { my_x($_[0]) },                 'direct passing (my $x)';

test_it sub { map local__($_), @_ },         'map (local $_)';
test_it sub { map local_g($_), @_ },         'map (local $g)';
test_it sub { map my_g($_), @_ },            'map (my $g)';
test_it sub { map my_x($_), @_ },            'map (my $x)';

test_it sub { for $g (@_) { local__($g) } }, 'for $g (local $_)';
test_it sub { for $g (@_) { local_g($g) } }, 'for $g (local $g)';
test_it sub { for $g (@_) { my_g($g) } },    'for $g (my $g)';
test_it sub { for $g (@_) { my_x($g) } },    'for $g (my $x)';

test_it sub { for (@_) { $g = $_; local__($g) } }, 'for copy of $g (local $_)';
test_it sub { for (@_) { $g = $_; local_g($g) } }, 'for copy of $g (local $g)';
test_it sub { for (@_) { $g = $_; my_g($g) } },    'for copy of $g (my $g)';
test_it sub { for (@_) { $g = $_; my_x($g) } },    'for copy of $g (my $x)';

sub local__ {
  local $_ = shift;
  s/o/a/ if $_;
  return $_;
}

sub local_g {
  local $g = shift;
  $g =~ s/o/a/ if $g;
  return $g;
}

sub my_g {
  my $g = shift;
  $g =~ s/o/a/ if $g;
  return $g;
}

sub my_x {
  my $x = shift;
  $x =~ s/o/a/ if $x;
  return $x;
}
#### END test script: threads_and_local.t



-----------------------------------------------------------------
---
Flags:
    category=library
    severity=low
---
Site configuration information for perl v5.8.4:

Configured by Debian Project at Tue Mar  8 20:31:23 EST 2005.

Summary of my perl5 (revision 5 version 8 subversion 4) configuration:
  Platform:
    osname=linux, osvers=2.4.27-ti1211, archname=i386-linux-thread-multi
    uname='linux kosh 2.4.27-ti1211 #1 sun sep 19 18:17:45 est 2004 i686 gnulinux '
    config_args='-Dusethreads -Duselargefiles -Dccflags=-DDEBIAN -Dcccdlflags=-fPIC -Darchname=i386-linux -Dprefix=/usr -Dprivlib=/usr/share/perl/5.8 -Darchlib=/usr/lib/perl/5.8 -Dvendorprefix=/usr -Dvendorlib=/usr/share/perl5 -Dvendorarch=/usr/lib/perl5 -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl/5.8.4 -Dsitearch=/usr/local/lib/perl/5.8.4 -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/man/man3 -Dsiteman1dir=/usr/local/man/man1 -Dsiteman3dir=/usr/local/man/man3 -Dman1ext=1 -Dman3ext=3perl -Dpager=/usr/bin/sensible-pager -Uafs -Ud_csh -Uusesfio -Uusenm -Duseshrplib -Dlibperl=libperl.so.5.8.4 -Dd_dosuid -des'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=define use5005threads=undef useithreads=define usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBIAN -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBIAN -fno-strict-aliasing -I/usr/local/include'
    ccversion='', gccversion='3.3.5 (Debian 1:3.3.5-9)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lgdbm -lgdbm_compat -ldb -ldl -lm -lpthread -lc -lcrypt
    perllibs=-ldl -lm -lpthread -lc -lcrypt
    libc=/lib/libc-2.3.2.so, so=so, useshrplib=true, libperl=libperl.so.5.8.4
    gnulibc_version='2.3.2'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:
    

---
@INC for perl v5.8.4:
    /home/duelafn/Perl/lib
    /home/duelafn/hyparr/mathlibs/GAP/lib
    /home/duelafn/hyparr/mathlibs/Macaulay/lib
    /home/duelafn/hyparr/mathlibs/TestIsom/lib
    /home/duelafn/hyparr/mathlibs/Result/lib
    /home/duelafn/hyparr/mathlibs/InteractiveProgram/lib
    /home/duelafn/hyparr/mathlibs/Singular/lib
    /home/duelafn/hyparr/mathlibs/Maple/lib
    /home/duelafn/hyparr/lib
    /etc/perl
    /usr/local/lib/perl/5.8.4
    /usr/local/share/perl/5.8.4
    /usr/lib/perl5
    /usr/share/perl5
    /usr/lib/perl/5.8
    /usr/share/perl/5.8
    /usr/local/lib/site_perl
    .

---
Environment for perl v5.8.4:
    HOME=/home/duelafn
    LANG=en_US.UTF-8
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/usr/games:/Local/bin:/usr/local/Singular/2-0-5/COMPILE/ix86-Linux:/home/duelafn/extra/bin:/home/duelafn/hyparr/bin:/Local/bin:/usr/local/Singular/2-0-5/COMPILE/ix86-Linux
    PERL5LIB=:/home/duelafn/Perl/lib:/home/duelafn/hyparr/mathlibs/GAP/lib:/home/duelafn/hyparr/mathlibs/Macaulay/lib:/home/duelafn/hyparr/mathlibs/TestIsom/lib:/home/duelafn/hyparr/mathlibs/Result/lib:/home/duelafn/hyparr/mathlibs/InteractiveProgram/lib:/home/duelafn/hyparr/mathlibs/Singular/lib:/home/duelafn/hyparr/mathlibs/Maple/lib:/home/duelafn/hyparr/lib
    PERL_BADLANG (unset)
    SHELL=/bin/bash


[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]