File: 59-yield-threads.t

package info (click to toggle)
libscope-upper-perl 0.25-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 536 kB
  • ctags: 78
  • sloc: perl: 6,745; makefile: 7
file content (46 lines) | stat: -rw-r--r-- 636 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!perl -T

use strict;
use warnings;

use lib 't/lib';
use Scope::Upper::TestThreads;

use Test::Leaner;

use Scope::Upper qw<yield UP>;

our $z;

sub up1 {
 my $tid  = threads->tid();
 local $z = $tid;
 my $p    = "[$tid] up1";

 usleep rand(1e6);

 my @res = (
  -1,
  do {
   my @dummy = (
    999,
    map {
     my $foo = yield $tid .. $tid + 2 => UP;
     fail "$p: not reached";
    } 666
   );
   fail "$p: not reached";
  },
  -2
 );

 is_deeply \@res, [ -1, $tid .. $tid + 2, -2 ], "$p: yielded correctly";
}

my @threads = map spawn(\&up1), 1 .. 30;

$_->join for @threads;

pass 'done';

done_testing(scalar(@threads) + 1);