File: threads.t

package info (click to toggle)
libset-object-perl 1.42-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 620 kB
  • sloc: perl: 1,069; makefile: 14
file content (68 lines) | stat: -rw-r--r-- 1,065 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use strict;
use Test::More;
use Config;
BEGIN {
    eval 'use threads';
    if ($@) {
      plan skip_all => 'threads missing';
      exit(0);
    }
    if ($] <= 5.010 && $Config{useithreads}) {
      plan skip_all => 'threads unstable < 5.10';
      exit(0);
    }
}
plan tests => 2;
use threads::shared;
use Set::Object;

my $sh = new Set::Object();
my $warnings;
share($sh);
#share($warnings);

$SIG{__WARN__} = sub { $warnings = 1; warn @_ };

my $t1 = threads->new(\&f1);
my $t2 = threads->new(\&f2);

main();

$t1->join;
$t2->join;
threads->yield;

is $warnings, undef;

while ($t1->is_running && $t2->is_running) {
  sleep(0.1);
}

TODO: {
  local $TODO = "Set::Object has still refcount issues with threads RT#22760";
  is (scalar($sh->members), 5);
}

sub f1{
  foreach my $i (1..100){
    my $d = $i % 10;
    $sh->remove($d) if $sh->element($d);
  }
}

sub f2{
  foreach my $i (1..100){
    my $d = $i % 10;
    $sh->remove($d);
    #$sh->element($d);
  }
}

sub main{
  my $d;
  foreach my $i (1..100){
    my $d = $i % 10;
    $sh->insert($d);
  }
}