]> git.vpit.fr Git - perl/modules/Variable-Magic.git/blobdiff - t/40-threads.t
Lock shared variables
[perl/modules/Variable-Magic.git] / t / 40-threads.t
index 0b16c6aeb44acc8e18a4ae81ef2b055acb7d57dd..d2c536eed190a11a0be6ebc4f1c748f5374bfc61 100644 (file)
@@ -51,7 +51,7 @@ sub try {
                      }
                      0
                     },
-         free    => sub { ++$destroyed; 0 },
+         free    => sub { lock $destroyed; ++$destroyed; 0 },
          op_info => $op_info
  };
  is($@,     '',    "wizard in thread $tid doesn't croak");
@@ -87,10 +87,18 @@ sub try {
 
 for my $dispell (1, 0) {
  for my $sig (undef, Variable::Magic::gensig()) {
-  $destroyed = 0;
+  {
+   lock $destroyed;
+   $destroyed = 0;
+  }
+
   my @t = map { threads->create(\&try, $dispell, $sig, $_) }
                                (VMG_OP_INFO_NAME) x 2, (VMG_OP_INFO_OBJECT) x 2;
   $_->join for @t;
-  is($destroyed, (1 - $dispell) * 4, 'destructors');
+
+  {
+   lock $destroyed;
+   is $destroyed, (1 - $dispell) * 4, 'destructors';
+  }
  }
 }