1use strict; 2use warnings; 3 4BEGIN { 5 use Config; 6 if (! $Config{'useithreads'}) { 7 print("1..0 # SKIP Perl not compiled with 'useithreads'\n"); 8 exit(0); 9 } 10} 11 12use threads; 13use Thread::Queue; 14 15BEGIN { # perl RT 133382 16if ($] == 5.008) { 17 require 't/test.pl'; # Test::More work-alike for Perl 5.8.0 18} else { 19 require Test::More; 20} 21Test::More->import(); 22} # end BEGIN 23plan('tests' => 19); 24 25my $q = Thread::Queue->new(1..10); 26ok($q, 'New queue'); 27 28$q->enqueue([ qw/foo bar/ ]); 29 30sub q_check 31{ 32 is($q->peek(3), 4, 'Peek at queue'); 33 is($q->peek(-3), 9, 'Negative peek'); 34 35 my $nada = $q->peek(20); 36 ok(! defined($nada), 'Big peek'); 37 $nada = $q->peek(-20); 38 ok(! defined($nada), 'Big negative peek'); 39 40 my $ary = $q->peek(-1); 41 is_deeply($ary, [ qw/foo bar/ ], 'Peek array'); 42 43 is($q->pending(), 11, 'Queue count in thread'); 44} 45 46threads->create(sub { 47 q_check(); 48 threads->create('q_check')->join(); 49})->join(); 50q_check(); 51 52exit(0); 53 54# EOF 55