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

panic: MUTEX_LOCK (22) [op.c:453] in Perl 5.10.0 on Debian #9698

Closed
p5pRT opened this issue Mar 31, 2009 · 9 comments
Closed

panic: MUTEX_LOCK (22) [op.c:453] in Perl 5.10.0 on Debian #9698

p5pRT opened this issue Mar 31, 2009 · 9 comments

Comments

@p5pRT
Copy link

p5pRT commented Mar 31, 2009

Migrated from rt.perl.org#64326 (status was 'resolved')

Searchable as RT64326$

@p5pRT
Copy link
Author

p5pRT commented Mar 31, 2009

From dfs@roaringpenguin.com

Created by dfs@roaringpenguin.com

This is a bug report for perl from dfs@​roaringpenguin.com,
generated with the help of perlbug 1.36 running under perl 5.10.0.

-----------------------------------------------------------------
In Perl 5.10.0, it does not seem possible to create an interpreter,
destroy it, and create another in the same process by following the
perlembed instructions. The attached test case works fine under
Debian Etch (perl 5.8.8); running "./configure && make && ./embperl"
prints "I'm very happy!" twice. On lenny running Perl 5.10.0, the first
one works, but then it prints​:

panic​: MUTEX_LOCK (22) [op.c​:453] at script.pl line 1.
BEGIN failed--compilation aborted at script.pl line 1.
panic​: MUTEX_LOCK (22) [op.c​:453] at script.pl line 1.

Adding a call to PERL_SET_INTERP(NULL) after calling perl_free fixes
the problem, but it seems wrong.

See attached tarball for test case.

Perl Info

Flags:
    category=core
    severity=medium

Site configuration information for perl 5.10.0:

Configured by Debian Project at Thu Jan  1 12:43:38 UTC 2009.

Summary of my perl5 (revision 5 version 10 subversion 0) configuration:
  Platform:
    osname=linux, osvers=2.6.26-1-686, archname=i486-linux-gnu-thread-multi
    uname='linux rebekka 2.6.26-1-686 #1 smp mon dec 15 18:15:07 utc 2008 i686 gnulinux '
    config_args='-Dusethreads -Duselargefiles -Dccflags=-DDEBIAN -Dcccdlflags=-fPIC -Darchname=i486-linux-gnu -Dprefix=/usr -Dprivlib=/usr/share/perl/5.10 -Darchlib=/usr/lib/perl/5.10 -Dvendorprefix=/usr -Dvendorlib=/usr/share/perl5 -Dvendorarch=/usr/lib/perl5 -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl/5.10.0 -Dsitearch=/usr/local/lib/perl/5.10.0 -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/man/man3 -Dsiteman1dir=/usr/local/man/man1 -Dsiteman3dir=/usr/local/man/man3 -Dman1ext=1 -Dman3ext=3perl -Dpager=/usr/bin/sensible-pager -Uafs -Ud_csh -Ud_ualarm -Uusesfio -Uusenm -DDEBUGGING=-g -Doptimize=-O2 -Duseshrplib -Dlibperl=libperl.so.5.10.0 -Dd_dosuid -des'
    hint=recommended, useposix=true, d_sigaction=define
    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 -DDEBIAN -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2 -g',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fno-strict-aliasing -pipe -I/usr/local/include'
    ccversion='', gccversion='4.3.2', 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 /usr/lib64
    libs=-lgdbm -lgdbm_compat -ldb -ldl -lm -lpthread -lc -lcrypt
    perllibs=-ldl -lm -lpthread -lc -lcrypt
    libc=/lib/libc-2.7.so, so=so, useshrplib=true, libperl=libperl.so.5.10.0
    gnulibc_version='2.7'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fPIC', lddlflags='-shared -O2 -g -L/usr/local/lib'

Locally applied patches:
    


@INC for perl 5.10.0:
    /etc/perl
    /usr/local/lib/perl/5.10.0
    /usr/local/share/perl/5.10.0
    /usr/lib/perl5
    /usr/share/perl5
    /usr/lib/perl/5.10
    /usr/share/perl/5.10
    /usr/local/lib/site_perl
    .


Environment for perl 5.10.0:
    HOME=/home/dfs
    LANG=en_CA
    LANGUAGE (unset)
    LC_ALL=C
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/dfs/bin:/usr/local/bin:/usr/bin:/bin:/usr/games
    PERL_BADLANG (unset)
    SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Mar 31, 2009

@p5pRT
Copy link
Author

p5pRT commented Apr 2, 2009

From @iabyn

On Tue, Mar 31, 2009 at 11​:38​:15AM -0700, David F. Skoll wrote​:

In Perl 5.10.0, it does not seem possible to create an interpreter,
destroy it, and create another in the same process by following the
perlembed instructions. The attached test case works fine under
Debian Etch (perl 5.8.8); running "./configure && make && ./embperl"
prints "I'm very happy!" twice. On lenny running Perl 5.10.0, the first
one works, but then it prints​:

panic​: MUTEX_LOCK (22) [op.c​:453] at script.pl line 1.
BEGIN failed--compilation aborted at script.pl line 1.
panic​: MUTEX_LOCK (22) [op.c​:453] at script.pl line 1.

Adding a call to PERL_SET_INTERP(NULL) after calling perl_free fixes
the problem, but it seems wrong.

The problem is that you are calling PERL_SYS_TERM() more than once;
its only designed to get called once. However, the documentation on that
is totally ambiguous, so I've just commited the following the development
branch of perl​:

commit eb53357
Author​: David Mitchell <davem@​iabyn.com>
Date​: Thu Apr 2 23​:09​:01 2009 +0100

  document PERL_SYS_INIT, PERL_SYS_TERM and that they should only be used once

Inline Patch
diff --git a/perl.h b/perl.h
index c890e1f..fb0c8b6 100644
--- a/perl.h
+++ b/perl.h
@@ -2680,6 +2680,25 @@ typedef struct clone_params CLONE_PARAMS;
 #  define PERL_SYS_INIT3_BODY(argvp,argcp,envp) PERL_SYS_INIT_BODY(argvp,argcp)
 #endif
 
+/*
+=for apidoc Am|void|PERL_SYS_INIT|int argc|char** argv
+Provides system-specific tune up of the C runtime environment necessary to
+run Perl interpreters. This should be called only once, before creating
+any Perl interpreters.
+
+=for apidoc Am|void|PERL_SYS_INIT3|int argc|char** argv|char** env
+Provides system-specific tune up of the C runtime environment necessary to
+run Perl interpreters. This should be called only once, before creating
+any Perl interpreters.
+
+=for apidoc Am|void|PERL_SYS_TERM|
+Provides system-specific clean up of the C runtime environment after
+running Perl interpreters. This should be called only once, after
+freeing any remaining Perl interpreters.
+
+=cut
+ */
+
 #define PERL_SYS_INIT(argc, argv)	Perl_sys_init(argc, argv)
 #define PERL_SYS_INIT3(argc, argv, env)	Perl_sys_init3(argc, argv, env)
 #define PERL_SYS_TERM()			Perl_sys_term()
diff --git a/pod/perlapi.pod b/pod/perlapi.pod
index 0687604..7498939 100644
--- a/pod/perlapi.pod
+++ b/pod/perlapi.pod
@@ -1207,6 +1207,50 @@ Found in file mathoms.c
 
 =back
 
+=head1 Functions in file perl.h
+
+
+=over 8
+
+=item PERL_SYS_INIT
+X<PERL_SYS_INIT>
+
+Provides system-specific tune up of the C runtime environment necessary to
+run Perl interpreters. This should be called only once, before creating
+any Perl interpreters.
+
+	void	PERL_SYS_INIT(int argc, char** argv)
+
+=for hackers
+Found in file perl.h
+
+=item PERL_SYS_INIT3
+X<PERL_SYS_INIT3>
+
+Provides system-specific tune up of the C runtime environment necessary to
+run Perl interpreters. This should be called only once, before creating
+any Perl interpreters.
+
+	void	PERL_SYS_INIT3(int argc, char** argv, char** env)
+
+=for hackers
+Found in file perl.h
+
+=item PERL_SYS_TERM
+X<PERL_SYS_TERM>
+
+Provides system-specific clean up of the C runtime environment after
+running Perl interpreters. This should be called only once, after
+freeing any remaining Perl interpreters.
+
+	void	PERL_SYS_TERM()
+
+=for hackers
+Found in file perl.h
+
+
+=back
+
 =head1 Functions in file pp_ctl.c
 
 
diff --git a/pod/perlembed.pod b/pod/perlembed.pod
index 39364eb..161e1ce 100644
--- a/pod/perlembed.pod
+++ b/pod/perlembed.pod
@@ -196,11 +196,16 @@ version of I<miniperlmain.c> containing the essentials of embedding:
 
 Notice that we don't use the C<env> pointer.  Normally handed to
 C<perl_parse> as its final argument, C<env> here is replaced by
-C<NULL>, which means that the current environment will be used.  The macros
-PERL_SYS_INIT3() and PERL_SYS_TERM() provide system-specific tune up 
-of the C runtime environment necessary to run Perl interpreters; since
-PERL_SYS_INIT3() may change C<env>, it may be more appropriate to provide
-C<env> as an argument to perl_parse().
+C<NULL>, which means that the current environment will be used.
+
+The macros PERL_SYS_INIT3() and PERL_SYS_TERM() provide system-specific
+tune up of the C runtime environment necessary to run Perl interpreters;
+they should only be called once regardless of how many interpreters you
+create or destroy. Call PERL_SYS_INIT3() before you create your first
+interpreter, and PERL_SYS_TERM() after you free your last interpreter.
+
+Since PERL_SYS_INIT3() may change C<env>, it may be more appropriate to
+provide C<env> as an argument to perl_parse().
 
 Now compile this program (I'll call it I<interp.c>) into an executable:
 


-- 

In England there is a special word which means the last sunshine
of the summer. That word is "spring".

@p5pRT
Copy link
Author

p5pRT commented Apr 2, 2009

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Apr 3, 2009

From @ntyni

On Tue, Mar 31, 2009 at 11​:38​:15AM -0700, David F. Skoll wrote​:

In Perl 5.10.0, it does not seem possible to create an interpreter,
destroy it, and create another in the same process by following the
perlembed instructions. The attached test case works fine under
Debian Etch (perl 5.8.8); running "./configure && make && ./embperl"
prints "I'm very happy!" twice. On lenny running Perl 5.10.0, the first
one works, but then it prints​:

panic​: MUTEX_LOCK (22) [op.c​:453] at script.pl line 1.
BEGIN failed--compilation aborted at script.pl line 1.
panic​: MUTEX_LOCK (22) [op.c​:453] at script.pl line 1.

This is also <http​://bugs.debian.org/522099>, and as discussed there,
it seems to be a misunderstanding about the needed arguments for
PERL_SYS_INIT3(). The test case calls the macro (twice) with the
perl_parse() arguments, but apparently the "real" main() argc, argv and
env are the right ones.

If this is correct, maybe the attached documentation patch would help
to avoid similar confusion in the future?
--
Niko Tyni ntyni@​debian.org

@p5pRT
Copy link
Author

p5pRT commented Apr 3, 2009

From @ntyni

0001-Clarify-PERL_SYS_INIT3-usage.patch
From 929aa4e752e0474630a4f957e012f131191a4054 Mon Sep 17 00:00:00 2001
From: Niko Tyni <ntyni@debian.org>
Date: Thu, 2 Apr 2009 20:54:10 +0300
Subject: [PATCH] Clarify PERL_SYS_INIT3() usage.

As seen in [perl #64326] and <http://bugs.debian.org/522099>, the
PERL_SYS_INIT3() documentation in perlembed.pod could be clearer about
the macro arguments.
---
 pod/perlembed.pod |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/pod/perlembed.pod b/pod/perlembed.pod
index 39364eb..3a16b98 100644
--- a/pod/perlembed.pod
+++ b/pod/perlembed.pod
@@ -202,6 +202,10 @@ of the C runtime environment necessary to run Perl interpreters; since
 PERL_SYS_INIT3() may change C<env>, it may be more appropriate to provide
 C<env> as an argument to perl_parse().
 
+Also notice that no matter what arguments you pass to perl_parse(),
+PERL_SYS_INIT3() must be invoked on the C main() argc, argv and env and
+only once.
+
 Now compile this program (I'll call it I<interp.c>) into an executable:
 
     % cc -o interp interp.c `perl -MExtUtils::Embed -e ccopts -e ldopts`
-- 
1.5.6.5

@p5pRT
Copy link
Author

p5pRT commented Apr 19, 2009

From @iabyn

On Thu, Apr 02, 2009 at 09​:07​:10PM +0300, Niko Tyni wrote​:

On Tue, Mar 31, 2009 at 11​:38​:15AM -0700, David F. Skoll wrote​:

In Perl 5.10.0, it does not seem possible to create an interpreter,
destroy it, and create another in the same process by following the
perlembed instructions. The attached test case works fine under
Debian Etch (perl 5.8.8); running "./configure && make && ./embperl"
prints "I'm very happy!" twice. On lenny running Perl 5.10.0, the first
one works, but then it prints​:

panic​: MUTEX_LOCK (22) [op.c​:453] at script.pl line 1.
BEGIN failed--compilation aborted at script.pl line 1.
panic​: MUTEX_LOCK (22) [op.c​:453] at script.pl line 1.

This is also <http​://bugs.debian.org/522099>, and as discussed there,
it seems to be a misunderstanding about the needed arguments for
PERL_SYS_INIT3(). The test case calls the macro (twice) with the
perl_parse() arguments, but apparently the "real" main() argc, argv and
env are the right ones.

If this is correct, maybe the attached documentation patch would help
to avoid similar confusion in the future?

Thanks, applied as 174c68d32e9e7f904e35e6bf157e59aa67b468ab

diff --git a/pod/perlembed.pod b/pod/perlembed.pod
index 39364eb..3a16b98 100644
--- a/pod/perlembed.pod
+++ b/pod/perlembed.pod
@​@​ -202,6 +202,10 @​@​ of the C runtime environment necessary to run Perl interpreters; since
PERL_SYS_INIT3() may change C<env>, it may be more appropriate to provide
C<env> as an argument to perl_parse().

+Also notice that no matter what arguments you pass to perl_parse(),
+PERL_SYS_INIT3() must be invoked on the C main() argc, argv and env and
+only once.
+
Now compile this program (I'll call it I<interp.c>) into an executable​:

 % cc \-o interp interp\.c \`perl \-MExtUtils&#8203;::Embed \-e ccopts \-e ldopts\`

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

@p5pRT
Copy link
Author

p5pRT commented Apr 22, 2009

From @iabyn

On Mon, Apr 20, 2009 at 12​:58​:33AM +0100, Dave Mitchell wrote​:

On Thu, Apr 02, 2009 at 09​:07​:10PM +0300, Niko Tyni wrote​:

On Tue, Mar 31, 2009 at 11​:38​:15AM -0700, David F. Skoll wrote​:

In Perl 5.10.0, it does not seem possible to create an interpreter,
destroy it, and create another in the same process by following the
perlembed instructions. The attached test case works fine under
Debian Etch (perl 5.8.8); running "./configure && make && ./embperl"
prints "I'm very happy!" twice. On lenny running Perl 5.10.0, the first
one works, but then it prints​:

panic​: MUTEX_LOCK (22) [op.c​:453] at script.pl line 1.
BEGIN failed--compilation aborted at script.pl line 1.
panic​: MUTEX_LOCK (22) [op.c​:453] at script.pl line 1.

This is also <http​://bugs.debian.org/522099>, and as discussed there,
it seems to be a misunderstanding about the needed arguments for
PERL_SYS_INIT3(). The test case calls the macro (twice) with the
perl_parse() arguments, but apparently the "real" main() argc, argv and
env are the right ones.

If this is correct, maybe the attached documentation patch would help
to avoid similar confusion in the future?

Thanks, applied as 174c68d32e9e7f904e35e6bf157e59aa67b468ab

Or, since I forgot to push, then later rebased, that's actually
31f6f5a

--
The Enterprise's efficient long-range scanners detect a temporal vortex
distortion in good time, allowing it to be safely avoided via a minor
course correction.
  -- Things That Never Happen in "Star Trek" #21

@p5pRT
Copy link
Author

p5pRT commented Jul 20, 2016

@dcollinsn - Status changed from 'open' to 'resolved'

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

1 participant