develooper Front page | perl.perl5.porters | Postings from January 2011

[perl #82994] Attributes are reapplied to shared state variables

David Leadbeater
January 30, 2011 06:09
[perl #82994] Attributes are reapplied to shared state variables
Message ID:
# New Ticket Created by  David Leadbeater 
# Please include the string:  [perl #82994]
# in the subject line of all future correspondence about this issue. 
# <URL: >

This is a bug report for perl from,
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 a1fba7eb664f6fea65549e94672040d8e47c905e,
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.

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;


[Please do not change anything below this line]
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
    osname=darwin, osvers=10.6.0, archname=darwin-thread-multi-2level
    uname='darwin 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
    cc='ccache cc', ccflags ='-fno-common -DPERL_DARWIN -no-cpp-precomp -DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include',
    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
  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:

Environment for perl 5.13.9:
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PERL_BADLANG (unset)
    SHELL=/bin/zsh Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About