1 package Scope::Upper::TestThreads;
6 use Config qw<%Config>;
8 use Scope::Upper qw<SU_THREADSAFE>;
10 use VPIT::TestHelpers;
14 Test::Leaner::diag(@_);
20 skip_all 'This Scope::Upper isn\'t thread safe' unless SU_THREADSAFE;
22 my $force = $ENV{PERL_SCOPE_UPPER_TEST_THREADS} ? 1 : !1;
23 skip_all 'This perl wasn\'t built to support threads'
24 unless $Config{useithreads};
25 skip_all 'perl 5.13.4 required to test thread safety'
26 unless $force or "$]" >= 5.013_004;
28 load_or_skip_all('threads', $force ? '0' : '1.67', [ ]);
35 if (do { local $@; eval { require Time::HiRes; 1 } }) {
36 defined and diag "Using Time::HiRes $_" for $Time::HiRes::VERSION;
37 $exports{usleep} = \&Time::HiRes::usleep;
39 diag 'Using fallback usleep';
40 $exports{usleep} = sub {
41 my $s = int($_[0] / 2.5e5);
47 while (my ($name, $code) = each %exports) {
49 *{$pkg.'::'.$name} = $code;
57 local $SIG{__WARN__} = sub { push @diag, "Thread creation warning: @_" };
60 push @diag, "Thread creation error: $@" if $@;
63 Test::Leaner::diag($_) for @diag;
65 return $thread ? $thread : ();