I'm not familiar with Perl's threading model.  Is it possible the END
block is being called for each thread?  I can see how that might cause
segfaults if a memory mapped library is moved from its original location
while still in use.  Some platforms don't handle that very well.

If that's the case, is there a way to ensure the library cleanup is only
performed in the main thread after all other threads are joined?

--Scott

-----Original Message-----
From: Steffen Mueller [mailto:[EMAIL PROTECTED] 
Sent: Sunday, April 13, 2008 2:57 AM
To: [email protected]
Subject: PAR::Packer segmentation fault with threads

Hi all,

PAR::Packer 0.977 and up kindly share segmentation faults with the user
for the following simple script (and other usages of threads):

#!/usr/bin/perl
use strict;
use warnings;
use threads;

sub start_thread {
   print "I am a thread.\n";
}

my $thread  = threads->create("start_thread");
$thread->join();
print "I am not a thread \n";

The segmentation fault happens on creating of the thread, as far as I
can tell.

I did a manual binary-search and found that the following change caused
the SEGV's to appear:

----------------------------------------------------------------------
r1890 (orig r553):  snstanton | 2007-12-06 19:53:53 +0100

Fixed a problem where a second invocation of a --clean app could end up
using the temp directory of the previous invocation while it is still 
being cleaned up.  This primarily happens on Windows because pids are 
recycled quickly.  The change is to rename the temp directory to a 
unique name before launching the background cleanup process.


For reference, the patch was to add the following lines to par.pl:

=== script/par.pl
==================================================================
--- script/par.pl       (revision 1878)
+++ script/par.pl       (revision 1890)
@@ -161,6 +161,7 @@
  END { if ($ENV{PAR_CLEAN}) {
      require File::Temp;
      require File::Basename;
+    require File::Spec;
      my $topdir = File::Basename::dirname($par_temp);
      outs(qq{Removing files in "$par_temp"});
      File::Find::finddepth(sub { ( -d ) ? rmdir : unlink }, $par_temp);
@@ -180,6 +181,21 @@
              UNLINK => 0,
          );

+        # Because the par_temp directory is going to be deleted in a
+        # background process, the parent process id may be reused 
before the
+        # background process completes.  To ensure that the temporary
+        # directory does not get reused while it is being deleted, try
to
+        # rename it to a name that is related to the temporary script
file.
+
+        my $tmpname = (File::Spec->splitpath($tmp->filename))[2]; # 
filename
+        $tmpname =~ s/\.[^.]*$/.dir/;
+        my $newDir = File::Spec->catpath(
+            (File::Spec->splitpath($par_temp))[0..1], $tmpname);
+        if (rename $par_temp, $newDir) {
+            outs("Renamed $par_temp to $newDir");
+            $par_temp = $newDir;
+        }
+
          if ($^O =~ m/win32/i) {
              print $tmp "


Removing them from SVN head "fixes" the problem.

Scott, do you have an idea what's going on?

Cheers,
Steffen

Reply via email to