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 15if ($] == 5.008) { 16 require 't/test.pl'; # Test::More work-alike for Perl 5.8.0 17} else { 18 require Test::More; 19} 20Test::More->import(); 21plan('tests' => 19); 22 23my $q = Thread::Queue->new(1..10); 24ok($q, 'New queue'); 25 26$q->enqueue([ qw/foo bar/ ]); 27 28sub q_check 29{ 30 is($q->peek(3), 4, 'Peek at queue'); 31 is($q->peek(-3), 9, 'Negative peek'); 32 33 my $nada = $q->peek(20); 34 ok(! defined($nada), 'Big peek'); 35 $nada = $q->peek(-20); 36 ok(! defined($nada), 'Big negative peek'); 37 38 my $ary = $q->peek(-1); 39 is_deeply($ary, [ qw/foo bar/ ], 'Peek array'); 40 41 is($q->pending(), 11, 'Queue count in thread'); 42} 43 44threads->create(sub { 45 q_check(); 46 threads->create('q_check')->join(); 47})->join(); 48q_check(); 49 50exit(0); 51 52# EOF 53