source: trunk/essentials/dev-lang/perl/t/op/threads.t

Last change on this file was 3181, checked in by bird, 18 years ago

perl 5.8.8

File size: 1.3 KB
Line 
1#!./perl
2BEGIN {
3 chdir 't' if -d 't';
4 @INC = '../lib';
5 require './test.pl'; # for which_perl() etc
6 $| = 1;
7}
8
9use strict;
10use Config;
11
12BEGIN {
13 if (!$Config{useithreads}) {
14 print "1..0 # Skip: no ithreads\n";
15 exit 0;
16 }
17 if ($ENV{PERL_CORE_MINITEST}) {
18 print "1..0 # Skip: no dynamic loading on miniperl, no threads\n";
19 exit 0;
20 }
21 plan(3);
22}
23use threads;
24
25# test that we don't get:
26# Attempt to free unreferenced scalar: SV 0x40173f3c
27fresh_perl_is(<<'EOI', 'ok', { }, 'delete() under threads');
28use threads;
29threads->new(sub { my %h=(1,2); delete $h{1}})->join for 1..2;
30print "ok";
31EOI
32
33#PR24660
34# test that we don't get:
35# Attempt to free unreferenced scalar: SV 0x814e0dc.
36fresh_perl_is(<<'EOI', 'ok', { }, 'weaken ref under threads');
37use threads;
38use Scalar::Util;
39my $data = "a";
40my $obj = \$data;
41my $copy = $obj;
42Scalar::Util::weaken($copy);
43threads->new(sub { 1 })->join for (1..1);
44print "ok";
45EOI
46
47#PR24663
48# test that we don't get:
49# panic: magic_killbackrefs.
50# Scalars leaked: 3
51fresh_perl_is(<<'EOI', 'ok', { }, 'weaken ref #2 under threads');
52package Foo;
53sub new { bless {},shift }
54package main;
55use threads;
56use Scalar::Util qw(weaken);
57my $object = Foo->new;
58my $ref = $object;
59weaken $ref;
60threads->new(sub { $ref = $object } )->join; # $ref = $object causes problems
61print "ok";
62EOI
Note: See TracBrowser for help on using the repository browser.