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

Attributes are reapplied to shared state variables #11096

Open
p5pRT opened this issue Jan 29, 2011 · 3 comments
Open

Attributes are reapplied to shared state variables #11096

p5pRT opened this issue Jan 29, 2011 · 3 comments

Comments

@p5pRT
Copy link

p5pRT commented Jan 29, 2011

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

Searchable as RT82994$

@p5pRT
Copy link
Author

p5pRT commented Jan 29, 2011

From @dgl

Created by @dgl

This is a bug report for perl from dgl@​dgl.cx,
generated with the help of perlbug 1.39 running under perl 5.13.9.

-----------------------------------------------------------------
The shared attribute does not appear to work to share a state
variable with a thread.

Part of this was fixed in a1fba7e,
but the following script doesn't work on blead.

If I either stop using threads (but keep the shared attribute) or
move the declaration of the state variable out of the sub then
things work.

---8<------------------------------------------------------------
use feature 'state';
use threads;
use threads​::shared;
use Test​::More;

{
  my %c : shared;

  sub cache_nostate {
  my($key, $value) = @​_;
  $c{$key} ||= $value;
  }
}

sub cache_state {
  my($key, $value) = @​_;
  state %c : shared;
  $c{$key} ||= $value;
}

is cache_state(1, 2), 2;
is cache_nostate(1, 2), 2;

async {
  sleep 1;
  is cache_state(1), 2;
  is cache_nostate(1), 2;
}->join;

done_testing;

Perl Info

Flags:
    category=core
    severity=low

Site configuration information for perl 5.13.9:

Configured by dgl at Sat Jan 29 15:32:49 GMT 2011.

Summary of my perl5 (revision 5 version 13 subversion 9) configuration:
  Local Commit: 2254794822af02a1b9d61bbc33687929558e7219
  Ancestor: 730d722868af591c6b1310890124de9afc83f9ee
  Platform:
    osname=darwin, osvers=10.6.0, archname=darwin-thread-multi-2level
    uname='darwin babadag.i.otherwize.co.uk 10.6.0 darwin kernel version 10.6.0: wed nov 10 18:13:17 pst 2010; root:xnu-1504.9.26~3release_i386 i386 '
    config_args='-Dusedevel -Dusedtrace -Dprefix=/Users/dgl/perls/blead-v5.13.9-165-g2254794 -Dcc=ccache cc -Dld=cc -Doptimize=-ggdb3 -Dusethreads -de'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=define, usemultiplicity=define
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='ccache cc', ccflags ='-fno-common -DPERL_DARWIN -no-cpp-precomp -DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include',
    optimize='-ggdb3',
    cppflags='-no-cpp-precomp -fno-common -DPERL_DARWIN -no-cpp-precomp -DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
    ccversion='', gccversion='4.2.1 (Apple Inc. build 5664)', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='env MACOSX_DEPLOYMENT_TARGET=10.3 cc', ldflags =' -fstack-protector -L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib
    libs=-ldbm -ldl -lm -lutil -lc
    perllibs=-ldl -lm -lutil -lc
    libc=/usr/lib/libc.dylib, so=dylib, useshrplib=false, libperl=libperl.a
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags=' -bundle -undefined dynamic_lookup -L/usr/local/lib -fstack-protector'

Locally applied patches:
    


@INC for perl 5.13.9:
    /Users/dgl/perls/blead-v5.13.9-165-g2254794/lib/site_perl/5.13.9/darwin-thread-multi-2level
    /Users/dgl/perls/blead-v5.13.9-165-g2254794/lib/site_perl/5.13.9
    /Users/dgl/perls/blead-v5.13.9-165-g2254794/lib/5.13.9/darwin-thread-multi-2level
    /Users/dgl/perls/blead-v5.13.9-165-g2254794/lib/5.13.9
    .


Environment for perl 5.13.9:
    DYLD_LIBRARY_PATH (unset)
    HOME=/Users/dgl
    LANG=en_GB.UTF-8
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/Users/dgl/.perl5/bin:/Users/dgl/bin:/sbin:/usr/sbin:/usr/local/sbin:/sw/bin:/sw/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
    PERL5LIB=
    PERL_BADLANG (unset)
    SHELL=/bin/zsh

@p5pRT
Copy link
Author

p5pRT commented Sep 19, 2016

From @dcollinsn

In 5.25.2​:

$ perl5.25.2-thread-multi 82994.pl
ok 1
ok 2
not ok 3
# Failed test at 82994.pl line 26.
# got​: undef
# expected​: '2'
ok 4
1..4
# Looks like you failed 1 test of 4.

--
Respectfully,
Dan Collins

@p5pRT
Copy link
Author

p5pRT commented Feb 17, 2017

@jkeenan - Status changed from 'new' to 'open'

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