Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[perl #31806] pio_registered_layers is a global

0 views
Skip to first unread message

Nicholas Clark

unread,
Oct 2, 2004, 9:19:12 AM10/2/04
to bugs-bi...@rt.perl.org
# New Ticket Created by Nicholas Clark
# Please include the string: [perl #31806]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org:80/rt3/Ticket/Display.html?id=31806 >


---
osname= freebsd
osvers= 5.2-beta
arch= i386-freebsd
cc= cc
---
Flags:
category=core
severity=high
ack=no
---
This started out as me trying to build parrot on FreeBSD, and finding it fails
tests due to a double free() warning not matching "expected" results.
(Also fails on OS X as its malloc() has automatic double free() warnings)

So I had a dig (valgrind on FreeBSD++), and it turns out that it's this line:

mem_sys_free(pio_registered_layers);

in PIO_finish.

gdb traceback:

Starting program: /home/nick/Parrot/parrot04/parrot t/op/interp_1.pasm
calling
In 2
ending

Breakpoint 1, PIO_finish (interpreter=0x8553c00) at io/io.c:325
325 for (layer = interpreter->piodata->default_stack; layer; ) {
(gdb) where
#0 PIO_finish (interpreter=0x8553c00) at io/io.c:325
#1 0x0809993b in Parrot_really_destroy (exit_code=0, vinterp=0x8553c00)
at src/inter_create.c:333
#2 0x080e0e4a in Parrot_exit (status=0) at src/exit.c:79
#3 0x0809949e in main (argc=1, argv=0xbfbfec08) at imcc/main.c:587
#4 0x08098112 in _start ()
(gdb) c
Continuing.

Breakpoint 1, PIO_finish (interpreter=0x82ee400) at io/io.c:325
325 for (layer = interpreter->piodata->default_stack; layer; ) {
(gdb) where
#0 PIO_finish (interpreter=0x82ee400) at io/io.c:325
#1 0x0809993b in Parrot_really_destroy (exit_code=0, vinterp=0x82ee400)
at src/inter_create.c:333
#2 0x080e0e4a in Parrot_exit (status=0) at src/exit.c:79
#3 0x0809949e in main (argc=1, argv=0xbfbfec08) at imcc/main.c:587
#4 0x08098112 in _start ()
(gdb) c
Continuing.
parrot in free(): warning: chunk is already free


It's being called from the same place, but for 2 different interpreters.
At first I was just going to patch it with:

pio_registered_layers = NULL;

after the free(), but than I thought "This is a bug, because I guess we
want to free it with the *last* interpreter, not the first".

But then I thought


AWOOGA! AWOOGA! GLOBAL VARIABLE. NOT IN AN INTERPRETER STRUCTURE.


And I'm not sure what the correct fix is. But it sure ain't threadsafe
currently.

Nicholas Clark
---
Summary of my parrot 0.1.0 configuration:
configdate='Sat Oct 2 10:23:19 2004'
Platform:
osname=freebsd, archname=i386-freebsd
jitcapable=1, jitarchname=i386-freebsd,
jitosname=FREEBSD, jitcpuarch=i386
execcapable=1
perl=/usr/bin/perl
Compiler:
cc='cc', ccflags='-DAPPLLIB_EXP="/usr/local/lib/perl5/5.6.1/BSDPAN" -I/usr/local/include',
Linker and Libraries:
ld='cc', ldflags='-Wl,-E -L/usr/local/lib',
cc_ldflags='',
libs='-lm -lcrypt -lutil -lc_r -lgmp'
Dynamic Linking:
so='.so', ld_shared='-shared -L/usr/local/lib',
ld_shared_flags=''
Types:
iv=long, intvalsize=4, intsize=4, opcode_t=long, opcode_t_size=4,
ptrsize=4, ptr_alignment=1 byteorder=1234,
nv=double, numvalsize=8, doublesize=8

---
Environment:
HOME LANG LANGUAGE LD_LIBRARY_PATH LOGDIR PATH SHELL

Jens Rieks

unread,
Oct 2, 2004, 10:51:09 AM10/2/04
to perl6-i...@perl.org
On Saturday 02 October 2004 15:19, Nicholas Clark wrote:
> # New Ticket Created by Nicholas Clark
> # Please include the string: [perl #31806]
> # in the subject line of all future correspondence about this issue.
> # <URL: http://rt.perl.org:80/rt3/Ticket/Display.html?id=31806 >
> So I had a dig (valgrind on FreeBSD++), and it turns out that it's this
> line:
>
> mem_sys_free(pio_registered_layers);
>
> in PIO_finish.
[snip]

> It's being called from the same place, but for 2 different interpreters.
> At first I was just going to patch it with:
>
> pio_registered_layers = NULL;
>
> after the free(), but than I thought "This is a bug, because I guess we
> want to free it with the *last* interpreter, not the first".
>
> But then I thought
>
>
> AWOOGA! AWOOGA! GLOBAL VARIABLE. NOT IN AN INTERPRETER STRUCTURE.
>
>
> And I'm not sure what the correct fix is. But it sure ain't threadsafe
> currently.
Should be fixed. At least, no test fails on OpenBSD now.

> Nicholas Clark
jens

Nicholas Clark

unread,
Oct 2, 2004, 11:50:54 AM10/2/04
to Jens Rieks, perl6-i...@perl.org
On Sat, Oct 02, 2004 at 04:51:09PM +0200, Jens Rieks wrote:
> Should be fixed. At least, no test fails on OpenBSD now.

No tests fail on FreeBSD or OS X now.

I'm not convinced that I want to close the bug, as I still don't think that
the code is threadsafe, as there are globals accessed without mutex protection.
However, I don't know how parrot is planning to do mutexes cross-platform.

Nicholas Clark

Jens Rieks

unread,
Oct 2, 2004, 2:15:57 PM10/2/04
to perl6-i...@perl.org
On Saturday 02 October 2004 17:50, Nicholas Clark wrote:
> No tests fail on FreeBSD or OS X now.
Great!

> I'm not convinced that I want to close the bug, as I still don't think that
> the code is threadsafe, as there are globals accessed without mutex
> protection. However, I don't know how parrot is planning to do mutexes
> cross-platform.

Yes, it is not really threadsafe. I think its better to open another ticket
for it, there are several "not threadsafe yet"-like comments in parrot's
sourcecode.

> Nicholas Clark
jens

Leopold Toetsch

unread,
Oct 3, 2004, 8:28:17 AM10/3/04
to perl6-i...@perl.org
Nicholas Clark <parrotbug...@parrotcode.org> wrote:

> mem_sys_free(pio_registered_layers);

Ah, yep.

> AWOOGA! AWOOGA! GLOBAL VARIABLE. NOT IN AN INTERPRETER STRUCTURE.

> And I'm not sure what the correct fix is. But it sure ain't threadsafe
> currently.

Interpreter (thread) destruction is done by aquiring the
C<interpreter_array_mutex>. C<pio_registered_layers> should of course be
freed only for the last interpreter that is that one w/o
C<interpreter->parent_interpreter>. The current fix is a bit too
complicated but ok.

But the first thing to solve is: should the IO subsystem be shared for
threads or separate. See another post WRT Cygwin thread problems.

> Nicholas Clark

leo

0 new messages