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
11 #########################
14 use ExtUtils::testlib;
16 BEGIN { print "1..12\n" };
24 #########################
26 # Insert your test code below, the Test module is use()ed here so read
27 # its man page ( perldoc Test ) for help writing this test script.
30 my ($id, $ok, $name) = @_;
32 # You have to do it this way or VMS will get confused.
33 print $ok ? "ok $id - $name\n" : "not ok $id - $name\n";
35 printf "# Failed test at line %d\n", (caller)[2] unless $ok;
43 #test passing of simple argument
44 my $thread = threads->create(sub { ok(2, 'bar' eq $_[0]),"" },"bar");
48 #test passing of complex argument
50 $thread = threads->create(sub { ok(3, 'bar' eq $_[0]->[0]->{foo})},[{foo => 'bar'}]);
55 #test execuion of normal sub
56 sub bar { ok(4,shift() == 1,"") }
57 threads->create(\&bar,1)->join();
61 ok(5, 1 == $Config::threads,"");
63 #test trying to detach thread
65 my $thread1 = threads->create(sub {ok(6,1,"")});
70 #create nested threads
71 unless($^O eq 'MSWin32') {
72 my $thread3 = threads->create(sub { threads->create(sub {})})->join();
78 unless($^O eq 'MSWin32') {
80 push @threads, threads->create(sub { for(1..100000) { my $i } threads->create(sub { sleep 2})->join() });
82 foreach my $thread (@threads) {
88 my $self = threads->self();
89 ok(9,$self->tid() == 57,"");
92 my $self = threads->self();
93 ok(10,$self->tid() == 58,"");
96 #check support for threads->self() in main thread
97 ok(11, 0 == threads->self->tid(),"");
98 ok(12, 0 == threads->tid(),"Check so that tid for threads work for current tid");