develooper Front page | perl.perl5.porters | Postings from September 2013

[perl #119897] glob in threads is broken in perl5.18

Thread Previous | Thread Next
From:
Father Chrysostomos via RT
Date:
September 21, 2013 00:16
Subject:
[perl #119897] glob in threads is broken in perl5.18
Message ID:
rt-3.6.HEAD-1873-1379722572-1846.119897-15-0@perl.org
On Fri Sep 20 16:31:00 2013, Hugmeir wrote:
> Yes. The problem for both is that x_GLOB_ENTRIES should be thread-local,
> but is unintentionally being shared between threads.
> 
> This patch solves the issue:
> 
> diff --git a/ext/File-Glob/Glob.xs b/ext/File-Glob/Glob.xs
> index b3705b3..181dbbc 100644
> --- a/ext/File-Glob/Glob.xs
> +++ b/ext/File-Glob/Glob.xs
> @@ -396,6 +396,13 @@ PPCODE:
>      iterate(aTHX_ doglob_iter_wrapper);
>      SPAGAIN;
> 
> +void
> +CLONE(...)
> +CODE:
> +    PERL_UNUSED_ARG(items);
> +    MY_CXT_CLONE;
> +    MY_CXT.x_GLOB_ENTRIES = NULL;
> +
>  BOOT:
>  {
>  #ifndef PERL_EXTERNAL_GLOB
> 
> 
> But it means that this:
> 
> ./perl -Ilib -Mthreads -E 'sub foo {scalar glob("*")} foo(); say
> threads->create(\&foo)->join() for 1..3'
> 
> Will return "Artistic" four times, rather than "Artristic" followed by the
> second file thrice. If the latter is the desired behavior, then we need to
> hv_dup(x_GLOB_ENTRIES) in CLONE() as well.

Yes, the latter.  That would be backward-compatible with when File::Glob
still worked.

Thank you for tackling this.  This is entirely my fault, as I was the
one who moved it from Perl space to XS.

-- 

Father Chrysostomos


---
via perlbug:  queue: perl5 status: open
https://rt.perl.org:443/rt3/Ticket/Display.html?id=119897

Thread Previous | 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