Debian Codegraph @

t/threads.t

raw symbols SCIP
1 #!/usr/bin/env perl
2
3 use strict;
4 use warnings;
5 use PDL::LiteF;
6
7 my $can_use_threads = eval 'use threads; 1'; ## no critic (eval)
8 use Test::More;
9 if( ! $can_use_threads ) {
10 plan skip_all => "perl does not support threads";
11 } else {
12 plan tests => 1;
13 $PDL::no_clone_skip_warning = 1;
14 require PDL::FFTW3;
15 PDL::FFTW3->import('rfft1');
16 require Thread::Semaphore;
17 }
18
19 my $s = Thread::Semaphore->new();
20
21 sub run_fft {
22 note "Running in thread #" . threads->self->tid;
23 for my $size_factor (1..10) {
24 my $xvals = sequence($size_factor * 100);
25 my $x = sin( $xvals * 2.0 ) + 2.0 * cos( $xvals / 3.0 );
26 my $F = rfft1( $x );
27 }
28 $s->down;
29
30 return 1;
31 }
32
33 subtest "Running FFTW in threads" => sub {
34 eval {
35 local $SIG{ALRM} = sub { die "alarm\n" };
36 alarm 4; # timeout in 4 seconds
37
38 my @threads;
39 for (0..7) {
40 push @threads, threads->create(\&run_fft);
41 $s->up;
42 }
43
44 $s->down;
45 for my $thr (@threads) {
46 my ($return) = $thr->join;
47 if( ! $return ) {
48 fail "Thread #@{[ $thr->tid ]} did not complete successfully";
49 return;
50 }
51 }
52
53 alarm 0;
54 };
55 if ($@) {
56 if($@ eq "alarm\n") {
57 fail "Threads hanging";
58 } else {
59 die $@;
60 }
61
62 }
63
64 pass "All threads returned successfully";
65 };
66
67 done_testing;