develooper Front page | perl.perl5.porters | Postings from October 2003

Re: [perl #24138] GLOB_ERROR shared across threads

Thread Previous
From:
Rafael Garcia-Suarez
Date:
October 7, 2003 15:40
Subject:
Re: [perl #24138] GLOB_ERROR shared across threads
Message ID:
20031008004209.4be912c3.rgarciasuarez@free.fr
mjp-perl-ZYsBlwkHGFY@pilcrow.madison.wi.us (via RT) wrote:
> Is it just me, or is File::Glob::GLOB_ERROR() inappropriately
> returning a global, shared value, rather than a thread-specific
> one?

No, GLOB_ERROR is actually stored in a thread specific place.
What happens is that it's not zero'ed again when the new interpreter
for the new thread is cloned. This is considered normal behaviour :
the new thread starts where the one who created it left.

I don't know if it's possible to register code to be called at
interpreter clone time. It so, we could make it reset GLOB_ERROR.

>   $ cat globbit.pl
>   use v5.8.1;
>   use threads;
>   use File::Glob ':glob';
>   use strict;
>   
>   sub e($) {
>     my $g = shift;
>     my $t = threads->tid;
>     print "Thread ", threads->tid, "\n";
>     print "\tinitial GLOB_ERROR: ", &GLOB_ERROR, "\n";
>     bsd_glob($g);
>     print "\tfinal GLOB_ERROR: ", &GLOB_ERROR, "\n";
>   }
>   
>   for (qw|/root/eacces* /tmp /*/*/*/*/*/*/*|) {
>     threads->create(\&e, $_)->join;
>   }
>   __END__  
> 
>   $ perl globbit.pl
>   Thread 1
>   	initial GLOB_ERROR: 0
>   	final GLOB_ERROR: -2
>   Thread 2
>   	initial GLOB_ERROR: -2
>   	final GLOB_ERROR: 0
>   Thread 3
>   	initial GLOB_ERROR: 0
>   	final GLOB_ERROR: -2

Thread Previous


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