[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]

Perl Test Program: thread/regexp



This is a new perl test program that is a variation of the tests that Brian and I used to
develop our fix for the regexp/thread problem.  It still works on our system; it used to
fail on the distribution.  (I hope that in preparing it for this message I didn't break
it, but I haven't installed the latest developers release to verify that it still fails.) 
Run it just like any of the other perl tests (after fixing the path). I hope that it will
allow others to implement the more general fix.

Note that if you attempt to fix this problem, Ilya can point you to a more general
solution than what we produced.

Rob
#!/opt/local/bin/perlthr -w
BEGIN {
    chdir 't' if -d 't';
    unshift @INC, '../lib';
    require Config; import Config;
    if (! $Config{'usethreads'}) {
	print "1..0 # Skip: this perl is not threaded\n";
	exit 0;
    }

    # XXX known trouble with global destruction
    # $ENV{PERL_DESTRUCT_LEVEL} = 0 unless $ENV{PERL_DESTRUCT_LEVEL} > 3;
}
$| = 1;
print "1..4\n";
use Thread qw(yield);
print "ok 1\n";
my $short = "This is a long string that goes on and on.";
my $shorte = " a long string that goes on and on.";
my $long  = "This is short.";
my $longe  = " short.";
my $thr1 = new Thread \&threaded, $short, $shorte, "2";
my $thr2 = new Thread \&threaded, $long, $longe, "3";

sub threaded {
  my ($string, $string_end, $testno) = @_;

  # Do the match, saving the output in appropriate variables
  $string =~ /(.*)(is)(.*)/;
  # Yield control, allowing the other thread to fill in the match variables
  yield();
  # Examine the match variable contents; on broken perls this fails
  if ($3 eq $string_end) {
    print "ok $testno\n";
  }
  else {
    print "not ok $testno...other thread filled in match variables\n";
  }
}
$thr1->join;
$thr2->join;
print "ok 4\n";

[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]