Front page | perl.perl5.porters |
Postings from January 2011
[perl #82994] Attributes are reapplied to shared state variables
From:
David Leadbeater
Date:
January 30, 2011 06:09
Subject:
[perl #82994] Attributes are reapplied to shared state variables
Message ID:
rt-3.6.HEAD-20807-1296325202-828.82994-75-0@perl.org
# New Ticket Created by David Leadbeater
# Please include the string: [perl #82994]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=82994 >
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 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.
---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;
[Please do not change anything below this line]
-----------------------------------------------------------------
---
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
-
[perl #82994] Attributes are reapplied to shared state variables
by David Leadbeater