4 # The reason this does not use a Test module is that
5 # they mess up test numbers between threads
7 # And even when that will be fixed, this is a basic
8 # test and should not rely on shared variables
10 # This will test the basic API, it will not use any coderefs
11 # as they are more advanced
13 #########################
19 require Config; import Config;
20 unless ($Config{'useithreads'}) {
21 print "1..0 # Skip: no useithreads\n";
26 use ExtUtils::testlib;
28 BEGIN { $| = 1; print "1..15\n" };
36 #########################
42 my ($id, $ok, $name) = @_;
44 # You have to do it this way or VMS will get confused.
45 print $ok ? "ok $id - $name\n" : "not ok $id - $name\n";
47 printf "# Failed test at line %d\n", (caller)[2] unless $ok;
55 ok(2,'bar' eq $_[0],"Test that argument passing works");
57 threads->create('test1','bar')->join();
60 ok(3,'bar' eq $_[0]->[0]->{foo},"Test that passing arguments as references work");
63 threads->create('test2',[{foo => 'bar'}])->join();
66 #test execuion of normal sub
67 sub test3 { ok(4,shift() == 1,"Test a normal sub") }
68 threads->create('test3',1)->join();
72 ok(5, 1 == $threads::threads,"Check that threads::threads is true");
74 #test trying to detach thread
76 sub test4 { ok(6,1,"Detach test") }
78 my $thread1 = threads->create('test4');
82 ok(7,1,"Detach test");
87 threads->create('test6')->join();
88 ok(9,1,"Nested thread test");
92 ok(8,1,"Nested thread test");
95 threads->create('test5')->join();
98 my $self = threads->self();
99 ok(10, $self->tid == 7, "Wanted 7, got ".$self->tid);
100 ok(11, threads->tid() == 7, "Wanted 7, got ".threads->tid());
103 threads->create('test7')->join;
106 my $self = threads->self();
107 ok(12, $self->tid == 8, "Wanted 8, got ".$self->tid);
108 ok(13, threads->tid() == 8, "Wanted 8, got ".threads->tid());
111 threads->create('test8')->join;
114 #check support for threads->self() in main thread
115 ok(14, 0 == threads->self->tid(),"Check so that tid for threads work for main thread");
116 ok(15, 0 == threads->tid(),"Check so that tid for threads work for main thread");