]> git.vpit.fr Git - perl/modules/Variable-Magic.git/blobdiff - t/41-clone.t
Share the vtables with threaded perls
[perl/modules/Variable-Magic.git] / t / 41-clone.t
index 0e47d3694819bc8c37a75cdfb411854dd7ab4aa6..1bfe6b5b3f5f53add4816fbf4aae2a131e6b936e 100644 (file)
@@ -97,3 +97,45 @@ for my $dispell (1, 0) {
   }
  }
 }
+
+{
+ my @threads;
+ my $flag : shared = 0;
+ my $destroyed;
+
+ {
+  my $wiz = wizard(
+   set => sub {
+    my $tid = threads->tid;
+    pass "set callback called in thread $tid"
+   },
+   free => sub { ++$destroyed },
+  );
+
+  my $var = 123;
+  cast $var, $wiz;
+
+  @threads = map spawn(
+   sub {
+    my $tid = threads->tid;
+    my $exp = 456 + $tid;
+    {
+     lock $flag;
+     threads::shared::cond_wait($flag) until $flag;
+    }
+    $var = $exp;
+    is $var, $exp, "\$var could be assigned to in thread $tid";
+   }
+  ), 1 .. 5;
+ }
+
+ is $destroyed, 1, 'wizard is destroyed';
+
+ {
+  lock $flag;
+  $flag = 1;
+  threads::shared::cond_broadcast($flag);
+ }
+
+ $_->join for @threads;
+}