Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Perl: porters

[perl #36664] Strange behavior of shared array

 

 

Perl porters RSS feed   Index | Next | Previous | View Threaded


perlbug-followup at perl

Jul 26, 2005, 8:09 PM

Post #1 of 2 (344 views)
Permalink
[perl #36664] Strange behavior of shared array

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


This is a bug report for perl from ikegami [at] artemis,
generated with the help of perlbug 1.35 running under perl v5.8.7.


-----------------------------------------------------------------
The following code snippet doesn't work as expected.

-----
#!/usr/bin/perl
use threads;
use threads::shared;

our @List : shared = (1..5);
my $v = 3.5;
$v > 0;
$List[3] = $v;
printf "\@List[(3)] = %s\n", @List[(3)];
printf "\$List[3] = %s\n", $List[3];
-----

The output looks like:
@List[(3)] = 3
$List[3] = 3.5

Without "use threads", both @List[(3)] and $List[3] are stringified as
"3.5". The "$v > 0" line is somehow essential for the reproduction;
when replaced with "$v > 0.5", the trouble vanishes.
-----------------------------------------------------------------
---
Flags:
category=core
severity=low
---
Site configuration information for perl v5.8.7:

Configured by ikegami at Thu Jun 16 22:21:09 JST 2005.

Summary of my perl5 (revision 5 version 8 subversion 7) configuration:
Platform:
osname=linux, osvers=2.4.18-3, archname=i686-linux-thread-multi
uname='linux artemis.a01.aist.go.jp 2.4.18-3 #1 thu apr 18 07:37:53 edt 2002 i686 unknown '
config_args='-ds -e -Dprefix=/usr -Dusethreads'
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 -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm',
optimize='-O2',
cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -fno-strict-aliasing -pipe -I/usr/local/include -I/usr/include/gdbm'
ccversion='', gccversion='2.96 20000731 (Red Hat Linux 7.3 2.96-110)', 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=-lnsl -lndbm -lgdbm -ldl -lm -lcrypt -lutil -lpthread -lc
perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
libc=/lib/libc-2.2.5.so, so=so, useshrplib=false, libperl=libperl.a
gnulibc_version='2.2.5'
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.7:
/home/ikegami/lib/perl
/usr/lib/perl5/5.8.7/i686-linux-thread-multi
/usr/lib/perl5/5.8.7
/usr/lib/perl5/site_perl/5.8.7/i686-linux-thread-multi
/usr/lib/perl5/site_perl/5.8.7
/usr/lib/perl5/site_perl/5.6.1
/usr/lib/perl5/site_perl/5.6.0
/usr/lib/perl5/site_perl
.

---
Environment for perl v5.8.7:
HOME=/home/ikegami
LANG=ja_JP.eucJP
LANGUAGE (unset)
LD_LIBRARY_PATH=/opt/intel_fc_80/lib:/opt/intel/compiler70/ia32/lib
LOGDIR (unset)
PATH=/home/ikegami/bin:/home/ikegami/util:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11R6/bin:/opt/intel_fc_80/bin:/opt/intel/compiler70/ia32/bin:/usr/java/j2re1.4.1/bin:/usr/java/j2sdk1.4.1/bin:/home/ikegami/ninf/linux/bin:.
PERL5LIB=/home/ikegami/lib/perl
PERL_BADLANG (unset)
SHELL=/bin/zsh


davem at iabyn

May 26, 2012, 12:17 AM

Post #2 of 2 (61 views)
Permalink
Re: [perl #36664] Strange behavior of shared array [In reply to]

On Fri, May 25, 2012 at 04:03:31PM -0700, Brian Fraser via RT wrote:
> On Fri May 25 15:15:19 2012, t-ikegami [at] aist wrote:
> > Dear Brian,
> >
> > Mmm, It seems that the behavior is changed, but not resolved yet. I
> > observe now
> >
> > @List[(3)] = 3
> > $List[3] = 3
> >
> > , which are not the expected results of
> >
> > @List[(3)] = 3.5
> > $List[3] = 3.5
> >
>
> Whoops, you are absolutely right; My mistake. Reopening.
>
> For some reason the shared SV doesn't keep the NOK flag, so it's
> incorrectly picking the IV slot. For the record, what Dave M's commit
> did was make the behavior consistent, but not correct it.

Note that this isn't specifically an issue with threads::shared, but a
general issue with tieing (which is how threads::shared is implemented);
this code produces the same bad result:

use Tie::Array;
tie our @List, 'Tie::StdArray';
@List = (1..5);
my $v = 3.5;
$v > 0;
$List[3] = $v;
printf "\@List[(3)] = %s\n", @List[(3)];
printf "\$List[3] = %s\n", $List[3];


--
"Foul and greedy Dwarf - you have eaten the last candle."
-- "Hordes of the Things", BBC Radio.

Perl porters RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.