File: threads2.t

package info (click to toggle)
libfunction-parameters-perl 2.002005-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 624 kB
  • sloc: perl: 3,945; makefile: 3
file content (38 lines) | stat: -rw-r--r-- 641 bytes parent folder | download | duplicates (3)
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
#!perl
use Test::More
    eval { require threads; threads->import; 1 }
        ? (tests => 1)
        : (skip_all => "threads required for testing threads");

use warnings FATAL => 'all';
use strict;

use threads::shared;

my $nthreads = 5;

my $xvar :shared = 0;

for my $t (1 .. $nthreads) {
    threads->create(sub {
        lock $xvar;
        $xvar++;
        cond_wait $xvar while $xvar >= 0;
        require Function::Parameters;
    });
}

{
    threads->yield;
    lock $xvar;
    if ($xvar < $nthreads) {
        redo;
    }

    $xvar = -1;
    cond_broadcast $xvar;
}

$_->join for threads->list;

pass "we haven't crashed yet";