On Tue May 25 01:42:10 2010, sprout wrote: > This is the result of this function in sv.c: > > DIR * > Perl_dirp_dup(pTHX_ DIR *const dp) > { > PERL_UNUSED_CONTEXT; > if (!dp) > return (DIR*)NULL; > /* XXX TODO */ > return dp; > } > > Unfortunately, I don’t know how to duplicate a directory handle > properly. > > The attached patch (not to be applied; just an example) makes a copy > using dup2, but the resulting dir handles share the same iterator > (i.e., the current behaviour, but without the crash). The code works > on Mac OS X, but I doubt it’s portable. I don’t know how to make it > work on other systems. > > I can see three ultimate solutions (in order of preference): > > a) Properly duplicate the dir handle so we have a new one with its own > iterator (I can’t find a fopendir function anywhere) > b) Simple duplicate the dir handle as in my example > c) Don’t copy dir handles into threads (return (DIR*)NULL; I tried > that and it works) > > If b or c happens, I think this needs to be documented in threads.pm. > We may have to choose between different items in the list at configure- > time, based on OS. > Attached is a patch to fix this. On systems with fchdir, it dwims (a). On other systems the dir handle is simply not passed to the thread (c).Thread Next