Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

threads::shared resets %hash iterators #9551

Open
p5pRT opened this issue Nov 1, 2008 · 4 comments
Open

threads::shared resets %hash iterators #9551

p5pRT opened this issue Nov 1, 2008 · 4 comments

Comments

@p5pRT
Copy link

p5pRT commented Nov 1, 2008

Migrated from rt.perl.org#60294 (status was 'open')

Searchable as RT60294$

@p5pRT
Copy link
Author

p5pRT commented Nov 1, 2008

From kbrintn@netstats-poll-07.ip.qwest.net

Created by kbrintn@netstats-poll-07.ip.qwest.net

I am passing a hash-of-hashes from one thread toa nother.

I found that if I iterate over the inner hashes with each
%{$outer{inner}}, it loops forever on the first key. It looks like every
use of $outer{inner} is resetting the hash iterator for the inner hash.

This program illustrates the problem​:

#################################################################

#!/usr/bin/perl

use strict;
use threads;
use threads​::shared;

my %outer :shared;

$outer{inner} = &share({});
%{$outer{inner}} = map { $_ => $_ } 'a'..'z';

###################################

print "threads version​: $threads​::VERSION\n";
print "threads​::shared version​: $threads​::shared​::VERSION\n";

print "By taking a reference first...\n";

my $iter = 0;
{
  my $ref = $outer{inner};
  while ($iter++ < 10)
  {
  last unless (my ($k, $v) = each %$ref);
  print "$k ";
  }
}

print " ...and so on\n\n";

###################################

print "By de-ref the shared hash-of-hashes each time...\n";

$iter = 0;
while ($iter++ < 10)
{
  last unless (my ($k, $v) = each %{$outer{inner}});
  print "$k ";
}

print " ...and so on\n";

#################################################################

On my system it outputs as follows​:

threads version​: 1.07
threads​::shared version​: 0.94
By taking a reference first...
w r a x d j y u k h ...and so on

By de-ref the shared hash-of-hashes each time...
w w w w w w w w w w ...and so on

Perl Info

Flags:
    category=core
    severity=low

Site configuration information for perl v5.8.8:

Configured by kbrintn at Fri Oct 31 20:44:57 UTC 2008.

Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
  Platform:
    osname=freebsd, osvers=7.0-release-p4, archname=i386-freebsd-thread-multi-64int
    uname='freebsd netstats-poll-07.ip.qwest.net 7.0-release-p4 freebsd 7.0-release-p4 #0: wed sep 10 23:44:36 utc 2008 kbrintn@netstats-poll-07.ip.qwest.net:usrobjusrsrcsysgeneric i386 '
    config_args='-sde -Dprefix=/usr/local -Darchlib=/usr/local/lib/perl5/5.8.8/mach -Dprivlib=/usr/local/lib/perl5/5.8.8 -Dman3dir=/usr/local/lib/perl5/5.8.8/perl/man/man3 -Dman1dir=/usr/local/man/man1 -Dsitearch=/usr/local/lib/perl5/site_perl/5.8.8/mach -Dsitelib=/usr/local/lib/perl5/site_perl/5.8.8 -Dscriptdir=/usr/local/bin -Dsiteman3dir=/usr/local/lib/perl5/5.8.8/man/man3 -Dsiteman1dir=/usr/local/man/man1 -Ui_malloc -Ui_iconv -Uinstallusrbinperl -Dcc=cc -Duseshrplib -Dccflags=-DAPPLLIB_EXP="/usr/local/lib/perl5/5.8.8/BSDPAN" -Doptimize=-g -DDEBUGGING -Ud_dosuid -Ui_gdbm -Dusethreads=y -Dusemymalloc=n -Duse64bitint'
    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=define use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-DAPPLLIB_EXP="/usr/local/lib/perl5/5.8.8/BSDPAN" -DHAS_FPSETMASK -DHAS_FLOATINGPOINT_H -DDEBUGGING -fno-strict-aliasing -pipe -Wdeclaration-after-statement -I/usr/local/include',
    optimize='-g',
    cppflags='-DAPPLLIB_EXP="/usr/local/lib/perl5/5.8.8/BSDPAN" -DHAS_FPSETMASK -DHAS_FLOATINGPOINT_H -DDEBUGGING -fno-strict-aliasing -pipe -Wdeclaration-after-statement -I/usr/local/include'
    ccversion='', gccversion='4.2.1 20070719  [FreeBSD]', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='cc', ldflags ='-pthread -Wl,-E -L/usr/local/lib'
    libpth=/usr/lib /usr/local/lib
    libs=-lm -lcrypt -lutil
    perllibs=-lm -lcrypt -lutil
    libc=, so=so, useshrplib=true, libperl=libperl.so
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='  -Wl,-R/usr/local/lib/perl5/5.8.8/mach/CORE'
    cccdlflags='-DPIC -fPIC', lddlflags='-shared  -L/usr/local/lib'

Locally applied patches:
    defined-or


@INC for perl v5.8.8:
    /usr/local/lib/perl5/5.8.8/BSDPAN
    /usr/local/lib/perl5/site_perl/5.8.8/mach
    /usr/local/lib/perl5/site_perl/5.8.8
    /usr/local/lib/perl5/site_perl/5.8.7
    /usr/local/lib/perl5/site_perl
    /usr/local/lib/perl5/5.8.8/mach
    /usr/local/lib/perl5/5.8.8
    .


Environment for perl v5.8.8:
    HOME=/home/kbrintn
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/kbrintn/rrdtool/run/bin:/home/kbrintn/.lib/bin/FreeBSD/7.0-RELEASE-p4/i386:/home/kbrintn/.lib/scripts:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin
    PERL_BADLANG (unset)
    SHELL=/bin/zsh

@p5pRT
Copy link
Author

p5pRT commented May 26, 2013

From @jkeenan

On Sat Nov 01 11​:30​:29 2008, kbrintn@​netstats-poll-07.ip.qwest.net wrote​:

This is a bug report for perl from kbrintn@​netstats-poll-
07.ip.qwest.net,
generated with the help of perlbug 1.35 running under perl v5.8.8.

-----------------------------------------------------------------
[Please enter your report here]

I am passing a hash-of-hashes from one thread toa nother.

I found that if I iterate over the inner hashes with each
%{$outer{inner}}, it loops forever on the first key. It looks like
every
use of $outer{inner} is resetting the hash iterator for the inner
hash.

This program illustrates the problem​:

#################################################################

#!/usr/bin/perl

use strict;
use threads;
use threads​::shared;

my %outer :shared;

$outer{inner} = &share({});
%{$outer{inner}} = map { $_ => $_ } 'a'..'z';

###################################

print "threads version​: $threads​::VERSION\n";
print "threads​::shared version​: $threads​::shared​::VERSION\n";

print "By taking a reference first...\n";

my $iter = 0;
{
my $ref = $outer{inner};
while ($iter++ < 10)
{
last unless (my ($k, $v) = each %$ref);
print "$k ";
}
}

print " ...and so on\n\n";

###################################

print "By de-ref the shared hash-of-hashes each time...\n";

$iter = 0;
while ($iter++ < 10)
{
last unless (my ($k, $v) = each %{$outer{inner}});
print "$k ";
}

print " ...and so on\n";

#################################################################

On my system it outputs as follows​:

threads version​: 1.07
threads​::shared version​: 0.94
By taking a reference first...
w r a x d j y u k h ...and so on

By de-ref the shared hash-of-hashes each time...
w w w w w w w w w w ...and so on

Is there anyone who has built a threaded perl on 5.18 who could check
out the issues raised in this older ticket?

Thank you very much.
Jim Keenan

@p5pRT
Copy link
Author

p5pRT commented May 26, 2013

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Jul 18, 2016

From @dcollinsn

On Sun May 26 10​:14​:27 2013, jkeenan wrote​:

Is there anyone who has built a threaded perl on 5.18 who could check
out the issues raised in this older ticket?

Thank you very much.
Jim Keenan

Yes. The problem in this ticket, if indeed it is a problem, is still present in 5.25.2.

dcollins@​nightshade64​:~/toolchain$ perl5.25.2-thread-multi 60294.pl
threads version​: 2.09
threads​::shared version​: 1.52
By taking a reference first...
c t w e v i p s x y ...and so on

By de-ref the shared hash-of-hashes each time...
c c c c c c c c c c ...and so on

The "address of" the hash, obtained by printing $outer{inner}, also changes every loop iteration. I am not surprised that this resets `each`.

--
Respectfully,
Dan Collins

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants