Retract the cond.t part of #16249 since the nature
[p5sagit/p5-mst-13.2.git] / ext / threads / t / list.t
1
2 BEGIN {
3     chdir 't' if -d 't';
4     @INC = qw(../lib .);
5     require Config; import Config;
6     unless ($Config{'useithreads'}) {
7         print "1..0 # Skip: no useithreads\n";
8         exit 0;
9     }
10     require "test.pl";
11 }
12
13 use ExtUtils::testlib;
14
15 use strict;
16
17
18 BEGIN { $| = 1; print "1..8\n" };
19
20 use_ok('threads');
21
22 ok(threads->self == (threads->list)[0]);
23
24
25 threads->create(sub {})->join();
26 ok(scalar @{[threads->list]} == 1);
27
28 my $thread = threads->create(sub {});
29 ok(scalar @{[threads->list]} == 2);
30 $thread->join();
31 ok(scalar @{[threads->list]} == 1);
32
33 curr_test(6);
34
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.
40
41 mkdir "thrsem", 0700;
42
43 $thread = threads->create(sub { my $ret = threads->self == (threads->list)[1];
44                                 rmdir "thrsem";
45                                 return $ret });
46
47 sleep 1 while -d "thrsem";
48
49 ok($thread == (threads->list)[1]);
50 ok($thread->join());
51 ok(scalar @{[threads->list]} == 1);
52
53 END {
54     1 while rmdir "thrsem";
55 }