+# Test simple clone
+
+SKIP: {
+ my $parent = spawn(sub {
+ my $here = 'simple clone, parent thread';
+ is_loaded 0, "$here, beginning";
+
+ do_load;
+ is_loaded 1, "$here, after loading";
+
+ SKIP: {
+ my $kid = spawn(sub {
+ my $here = 'simple clone, child thread';
+
+ is_loaded 1, "$here, beginning";
+
+ return;
+ });
+
+ skip "$could_not_create_thread (simple clone child)" => 1
+ unless defined $kid;
+
+ $kid->join;
+ if (my $err = $kid->error) {
+ die "in child thread: $err\n";
+ }
+ }
+
+ is_loaded 1, "$here, after child terminated";
+
+ return;
+ });
+
+ skip "$could_not_create_thread (simple clone parent)" => (3 + 1)
+ unless defined $parent;
+
+ $parent->join;
+ if (my $err = $parent->error) {
+ die $err;
+ }
+}
+
+is_loaded 0, 'main body, after simple clone';
+
+# Test clone outliving its parent
+
+SKIP: {
+ my $kid_done;
+ share($kid_done);
+
+ my $parent = spawn(sub {
+ my $here = 'outliving clone, parent thread';
+ is_loaded 0, "$here, beginning";
+
+ do_load;
+ is_loaded 1, "$here, after loading";
+
+ my $kid_tid;
+
+ SKIP: {
+ my $kid = spawn(sub {
+ my $here = 'outliving clone, child thread';
+
+ is_loaded 1, "$here, beginning";
+
+ {
+ lock $kid_done;
+ cond_wait $kid_done until $kid_done;
+ }
+
+ is_loaded 1, "$here, end";
+
+ return 1;
+ });
+
+ if (defined $kid) {
+ $kid_tid = $kid->tid;
+ } else {
+ $kid_tid = 0;
+ skip "$could_not_create_thread (outliving clone child)" => 2;
+ }
+ }
+
+ is_loaded 1, "$here, end";
+
+ return $kid_tid;
+ });
+
+ skip "$could_not_create_thread (outliving clone parent)" => (3 + 2)
+ unless defined $parent;
+
+ my $kid_tid = $parent->join;
+ if (my $err = $parent->error) {
+ die $err;
+ }
+
+ if ($kid_tid) {
+ my $kid = threads->object($kid_tid);
+ if (defined $kid) {
+ if ($kid->is_running) {
+ lock $kid_done;
+ $kid_done = 1;
+ cond_signal $kid_done;
+ }
+
+ $kid->join;
+ }
+ }
+}
+
+is_loaded 0, 'main body, after outliving clone';
+