5 require Config; import Config;
6 unless ($Config{'useithreads'}) {
7 print "1..0 # Skip: no useithreads\n";
13 use ExtUtils::testlib;
18 BEGIN { $| = 1; print "1..8\n" };
22 ok(threads->self == (threads->list)[0]);
25 threads->create(sub {})->join();
26 ok(scalar @{[threads->list]} == 1);
28 my $thread = threads->create(sub {});
29 ok(scalar @{[threads->list]} == 2);
31 ok(scalar @{[threads->list]} == 1);
35 # Just a sleep() would not guarantee that we sleep and will not
36 # wake up before the just created thread finishes. Instead, let's
37 # use the filesystem as a semaphore. Creating a directory and removing
38 # it should be a reasonably atomic operation even over NFS.
39 # Also, we do not want to depend here on shared variables.
43 $thread = threads->create(sub { my $ret = threads->self == (threads->list)[1];
47 sleep 1 while -d "thrsem";
49 ok($thread == (threads->list)[1]);
51 ok(scalar @{[threads->list]} == 1);
54 1 while rmdir "thrsem";