Commit | Line | Data |
7473853a |
1 | use strict; |
13c1b207 |
2 | use warnings; |
49485a95 |
3 | |
4 | BEGIN { |
7473853a |
5 | if ($ENV{'PERL_CORE'}){ |
6 | chdir 't'; |
7 | unshift @INC, '../lib'; |
8 | } |
9 | use Config; |
10 | if (! $Config{'useithreads'}) { |
6c791b15 |
11 | print("1..0 # SKIP Perl not compiled with 'useithreads'\n"); |
7473853a |
12 | exit(0); |
49485a95 |
13 | } |
14 | } |
15 | |
7473853a |
16 | use ExtUtils::testlib; |
49485a95 |
17 | |
18 | sub ok { |
19 | my ($id, $ok, $name) = @_; |
20 | |
21 | # You have to do it this way or VMS will get confused. |
7473853a |
22 | if ($ok) { |
23 | print("ok $id - $name\n"); |
24 | } else { |
25 | print("not ok $id - $name\n"); |
26 | printf("# Failed test at line %d\n", (caller)[2]); |
27 | } |
49485a95 |
28 | |
7473853a |
29 | return ($ok); |
6b85e4fe |
30 | } |
31 | |
7473853a |
32 | BEGIN { |
33 | $| = 1; |
34 | print("1..16\n"); ### Number of tests that will be run ### |
35 | }; |
49485a95 |
36 | |
49485a95 |
37 | use threads; |
38 | use threads::shared; |
7473853a |
39 | ok(1, 1, 'Loaded'); |
40 | |
41 | ### Start of Testing ### |
42 | |
49485a95 |
43 | my %hash; |
44 | share(%hash); |
45 | $hash{"foo"} = "bar"; |
46 | ok(2,$hash{"foo"} eq "bar","Check hash get"); |
47 | threads->create(sub { $hash{"bar"} = "thread1"})->join(); |
48 | threads->create(sub { ok(3,$hash{"bar"} eq "thread1", "Check thread get and write")})->join(); |
49 | { |
50 | my $foo = delete($hash{"bar"}); |
51 | ok(4, $foo eq "thread1", "Check delete, want 'thread1' got '$foo'"); |
52 | $foo = delete($hash{"bar"}); |
13c1b207 |
53 | ok(5, !defined $foo, "Check delete on empty value"); |
49485a95 |
54 | } |
55 | ok(6, keys %hash == 1, "Check keys"); |
56 | $hash{"1"} = 1; |
57 | $hash{"2"} = 2; |
58 | $hash{"3"} = 3; |
59 | ok(7, keys %hash == 4, "Check keys"); |
13c1b207 |
60 | ok(8, exists($hash{"1"}), "Exist on existing key"); |
61 | ok(9, !exists($hash{"4"}), "Exists on non existing key"); |
49485a95 |
62 | my %seen; |
63 | foreach my $key ( keys %hash) { |
64 | $seen{$key}++; |
65 | } |
66 | ok(10, $seen{1} == 1, "Keys.."); |
67 | ok(11, $seen{2} == 1, "Keys.."); |
68 | ok(12, $seen{3} == 1, "Keys.."); |
69 | ok(13, $seen{"foo"} == 1, "Keys.."); |
680c9d89 |
70 | |
71 | # bugid #24407: the stringification of the numeric 1 got allocated to the |
72 | # wrong thread memory pool, which crashes on Windows. |
73 | ok(14, exists $hash{1}, "Check numeric key"); |
74 | |
49485a95 |
75 | threads->create(sub { %hash = () })->join(); |
680c9d89 |
76 | ok(15, keys %hash == 0, "Check clear"); |
7473853a |
77 | |
78 | ok(16, is_shared(%hash), "Check for sharing"); |
79 | |
6c791b15 |
80 | exit(0); |
81 | |
7473853a |
82 | # EOF |