This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Gisle noted an unused variable
[perl5.git] / t / op / threads.t
CommitLineData
f935b2f6
SB
1#!./perl
2BEGIN {
3 chdir 't' if -d 't';
996dc718 4 @INC = '../lib';
f935b2f6
SB
5 require './test.pl'; # for which_perl() etc
6}
7
8use strict;
9use Config;
10
11BEGIN {
12 if (!$Config{useithreads}) {
13 print "1..0 # Skip: no ithreads\n";
14 exit 0;
15 }
6765206c
NC
16 if ($ENV{PERL_CORE_MINITEST}) {
17 print "1..0 # Skip: no dynamic loading on miniperl, no threads\n";
18 exit 0;
f935b2f6
SB
19 }
20 plan(3);
21}
6765206c 22use threads;
f935b2f6
SB
23
24# test that we don't get:
25# Attempt to free unreferenced scalar: SV 0x40173f3c
26fresh_perl_is(<<'EOI', 'ok', { }, 'delete() under threads');
27use threads;
28threads->new(sub { my %h=(1,2); delete $h{1}})->join for 1..2;
29print "ok";
30EOI
31
32#PR24660
33# test that we don't get:
34# Attempt to free unreferenced scalar: SV 0x814e0dc.
35fresh_perl_is(<<'EOI', 'ok', { }, 'weaken ref under threads');
36use threads;
37use Scalar::Util;
38my $data = "a";
39my $obj = \$data;
40my $copy = $obj;
41Scalar::Util::weaken($copy);
42threads->new(sub { 1 })->join for (1..1);
43print "ok";
44EOI
45
46#PR24663
47# test that we don't get:
48# panic: magic_killbackrefs.
49# Scalars leaked: 3
50fresh_perl_is(<<'EOI', 'ok', { }, 'weaken ref #2 under threads');
51package Foo;
52sub new { bless {},shift }
53package main;
54use threads;
55use Scalar::Util qw(weaken);
56my $object = Foo->new;
57my $ref = $object;
58weaken $ref;
59threads->new(sub { $ref = $object } )->join; # $ref = $object causes problems
60print "ok";
61EOI