develooper Front page | perl.perl5.porters | Postings from December 2015

[perl #126957] Incompatibility of Tie::Scalar and threads

Thread Next
From:
perlbug-followup
Date:
December 18, 2015 16:26
Subject:
[perl #126957] Incompatibility of Tie::Scalar and threads
Message ID:
rt-4.0.18-9550-1450436751-1285.126957-75-0@perl.org
# New Ticket Created by   
# Please include the string:  [perl #126957]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=126957 >


This is a bug report for perl from torsten.werner@assyst-intl.com,
generated with the help of perlbug 1.39 running under perl 5.16.3.

there is an incompatibility between threads and Tie::Scalar.

The problem happens on both Linux and Windows:
Linux: perl 5, version 20, subversion 1 (v5.20.1) built for 
x86_64-linux-thread-multi 
Win32: perl 5, version 16, subversion 3 (v5.16.3) built for 
MSWin32-x86-multi-thread

The documentation says, it is possible to define a DESTROY routine for a 
tied scalar.
The routine should be called during destruction of the instance.
The DESTROY routine is not called when both of the following happens:
 - a thread is running (the detach in the sample code avoids warnings, it 
happens without detach too)
 - the tied variable is used inside a function
it is not needed to call the function, referencing the variable in the 
code is enough to
reproduce the problem (see below)
it is not needed to do something with the tied variable in the thread, the 
existency of a thread is enough

the sample code below will print the following:

Destroy 456

the following is expected:

Destroy 456
Destroy 123

you get the expected output when you do one of the following
- comment out the line to create the thread
- comment out the assignment inside sub 

########################## snip here ###########################

use strict;

# this is the sample code for Tie::Scalar, but with a DESTROY handler 
instead FETCH:
package NewStdScalar;
require Tie::Scalar;
 
our @ISA = qw(Tie::StdScalar);
 
sub DESTROY 
{
        my $x=shift;
        print "Destroy $$x\n";
}
 
package main;

use threads;

sub dummy
{
        do {sleep 1} while 1;
}

# either comment out the following line to get the expected behavior
threads->create(\&dummy)->detach();
 
tie my $used_in_sub, 'NewStdScalar';
tie my $not_used_in_sub, 'NewStdScalar';


$used_in_sub=123;
$not_used_in_sub=456;

sub foo ()
{
# or comment out the following line to get the expected behavior
        print $used_in_sub;
}

exit;

########################## snip here ###########################

---
Flags:
    category=library
    severity=medium
    module=Tie::Scalar
---
Site configuration information for perl 5.16.3:

Configured by gecko at Mon Apr 14 14:24:55 2014.

Summary of my perl5 (revision 5 version 16 subversion 3) configuration:
 
  Platform:
    osname=MSWin32, osvers=5.2, archname=MSWin32-x86-multi-thread
    uname=''
    config_args='undef'
    hint=recommended, useposix=true, d_sigaction=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='C:\Perl64\site\bin\gcc.exe', ccflags ='-DNDEBUG -DWIN32 -D_CONSOLE 
-DNO_STRICT -DPERL_TEXTMODE_SCRIPTS -DUSE_SITECUSTOMIZE 
-DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO 
-D_USE_32BIT_TIME_T -DHASATTRIBUTE -fno-strict-aliasing -mms-bitfields',
    optimize='-O2',
    cppflags='-DWIN32'
    ccversion='', gccversion='gcc.exe (rubenvb-4.5.4) 4.5.4', 
gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=8
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='__int64', 
lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='C:\Perl64\site\bin\g++.exe', ldflags ='-L"C:\Perl\lib\CORE"'
    libpth=\lib
    libs=-lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 
-lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm 
-lversion -lodbc32 -lodbccp32 -lcomctl32 -lmsvcrt
    perllibs=-lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 
-lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm 
-lversion -lodbc32 -lodbccp32 -lcomctl32 -lmsvcrt
    libc=msvcrt.lib, so=dll, useshrplib=true, libperl=perl516.lib
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags='-mdll -L"C:\Perl\lib\CORE"'

Locally applied patches:
    ACTIVEPERL_LOCAL_PATCHES_ENTRY

---
@INC for perl 5.16.3:
    C:/Perl/site/lib
    C:/Perl/lib
    .

---
Environment for perl 5.16.3:
    HOME (unset)
    LANG=DE
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=C:\Program Files (x86)\ActiveState Perl Dev Kit 
9.3\bin\;C:\Program Files\ActiveState Perl Dev Kit 9.4\bin\;C:\Program 
Files (x86)\NVIDIA 
Corporation\PhysX\Common;C:\oracle\product\11.2.0.3\cli_32\bin;C:\oracle\product\11.2.0.3\db_64\bin;C:\Perl\site\bin;C:\Perl\bin;C:\Perl64\site\bin;C:\Perl64\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program 
Files 
(x86)\cvsnt;C:\bin;C:\Tools;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program 
Files (x86)\Microsoft SQL Server\90\Tools\binn\;C:\Program Files 
(x86)\GnuWin32\bin;C:\Program Files (x86)\Skype\Phone\;C:\Program Files 
(x86)\ActiveState Perl Dev Kit 9.3\bin\;C:\Program Files\ActiveState Perl 
Dev Kit 9.4\bin\;C:\Program Files (x86)\NVIDIA 
Corporation\PhysX\Common;C:\oracle\product\11.2.0.3\cli_32\bin;C:\oracle\product\11.2.0.3\db_64\bin;C:\Perl\site\bin;C:\Perl\bin;C:\Perl64\site\bin;C:\Perl64\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program 
Files 
(x86)\cvsnt;C:\bin;C:\Tools;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program 
Files (x86)\Microsoft SQL Server\90\Tools\binn\;C:\Program Files 
(x86)\GnuWin32\bin;C:\Program Files (x86)\Skype\Phone\
    PERL_BADLANG (unset)
    SHELL (unset)
----------------------------------------------------------------------

Assyst GmbH
Dr. Ing. Torsten Werner
Product Manager plan.assyst
Max-Planck-Str. 3
85609 Aschheim-Dornach
Germany
Phone:     +49 (0)89 90505-0
Fax:       +49 (0)89 90505-271
E-Mail:    torsten.werner@assyst.de
Internet:  http://www.assyst.de


Geschäftsführer: Dr. Andreas Seidl
Eingetragen beim Registergericht München HRB 180174
Sitz der Gesellschaft: 85609 Aschheim-Dornach
----------------------------------------------------------------------


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About