From: Jerry D. Hedden Date: Mon, 12 Feb 2007 12:04:33 +0000 (-0800) Subject: Use newer 'threads' constructs X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=878090d5582120ef9336936d4fc06895b4fd242a;p=p5sagit%2Fp5-mst-13.2.git Use newer 'threads' constructs From: "Jerry D. Hedden" Message-ID: <844555.64815.qm@web30202.mail.mud.yahoo.com> p4raw-id: //depot/perl@30310 --- diff --git a/ext/XS/APItest/t/my_cxt.t b/ext/XS/APItest/t/my_cxt.t index 0b1c371..2c34794 100644 --- a/ext/XS/APItest/t/my_cxt.t +++ b/ext/XS/APItest/t/my_cxt.t @@ -50,7 +50,7 @@ sub do_thread { SKIP: { skip "No threads", 4 unless $threads; - threads->new(\&do_thread)->join; + threads->create(\&do_thread)->join; } is(my_cxt_getint(), 1234, "int value preserved after join"); diff --git a/ext/threads/shared/t/blessed.t b/ext/threads/shared/t/blessed.t index 157bb53..9938ad0 100644 --- a/ext/threads/shared/t/blessed.t +++ b/ext/threads/shared/t/blessed.t @@ -48,7 +48,7 @@ my $sref = \do{ my $x }; share($sref); $sobj = $sref; -threads->new(sub { +threads->create(sub { # Bless objects bless $hobj, 'foo'; bless $aobj, 'bar'; @@ -99,7 +99,7 @@ ok(23, ref($$hobj{'array'}) eq 'yang', "blessed array in hash"); ok(24, ref($$hobj{'scalar'}) eq 'baz', "blessed scalar in hash"); ok(25, ${$$hobj{'scalar'}} eq '3', "blessed scalar in hash contents"); -threads->new(sub { +threads->create(sub { # Rebless objects bless $hobj, 'oof'; bless $aobj, 'rab'; diff --git a/ext/threads/shared/t/cond.t b/ext/threads/shared/t/cond.t index 08b2d30..7f18950 100644 --- a/ext/threads/shared/t/cond.t +++ b/ext/threads/shared/t/cond.t @@ -212,7 +212,7 @@ $Base++; lock($counter); if ($n > 0) { $counter++; - $th = threads->new(\&broad, $n-1); + $th = threads->create(\&broad, $n-1); cond_wait($counter); $counter += 10; } @@ -224,7 +224,7 @@ $Base++; $th->join if $th; } - threads->new(\&broad, 3)->join; + threads->create(\&broad, 3)->join; ok(2, $counter == 33, "cond_broadcast: all three threads woken"); $Base += 2; @@ -243,7 +243,7 @@ $Base++; lock($r); if ($n > 0) { $$r++; - $th = threads->new(\&broad2, $n-1); + $th = threads->create(\&broad2, $n-1); cond_wait($r); $$r += 10; } @@ -255,7 +255,7 @@ $Base++; $th->join if $th; } - threads->new(\&broad2, 3)->join;; + threads->create(\&broad2, 3)->join;; ok(2, $$r == 33, "cond_broadcast: ref: all three threads woken"); $Base += 2; diff --git a/ext/threads/shared/t/hv_refs.t b/ext/threads/shared/t/hv_refs.t index 938f7a7..cc57a34 100644 --- a/ext/threads/shared/t/hv_refs.t +++ b/ext/threads/shared/t/hv_refs.t @@ -97,7 +97,7 @@ ok(10, keys %foo == 0, "And make sure we realy have deleted the values"); } { my $object : shared = &share({}); - threads->new(sub { + threads->create(sub { bless $object, 'test1'; })->join; ok(16, ref($object) eq 'test1', "blessing does work"); diff --git a/ext/threads/threads.xs b/ext/threads/threads.xs index eb96414..1662ee8 100755 --- a/ext/threads/threads.xs +++ b/ext/threads/threads.xs @@ -637,7 +637,7 @@ S_ithread_create( * 1 ref to be the responsibility of join/detach, so we don't get * freed until join/detach, even if no thread objects remain. * This allows the following to work: - * { threads->new(sub{...}); } threads->object(1)->join; + * { threads->create(sub{...}); } threads->object(1)->join; */ thread->count = 3; diff --git a/lib/Thread/Queue.t b/lib/Thread/Queue.t index 33c420b..b0d8c0a 100644 --- a/lib/Thread/Queue.t +++ b/lib/Thread/Queue.t @@ -27,7 +27,7 @@ sub ok { } sub reader { - my $tid = threads->self->tid; + my $tid = threads->tid; my $i = 0; while (1) { $i++; @@ -49,7 +49,7 @@ my $nthreads = 5; my @threads; for (my $i = 0; $i < $nthreads; $i++) { - push @threads, threads->new(\&reader, $i); + push @threads, threads->create(\&reader, $i); } for (my $i = 1; $i <= 20; $i++) { diff --git a/lib/perl5db.pl b/lib/perl5db.pl index 1b9f376..9f5d3b1 100644 --- a/lib/perl5db.pl +++ b/lib/perl5db.pl @@ -1849,7 +1849,7 @@ sub DB { lock($DBGR); my $tid; if ($ENV{PERL5DB_THREADED}) { - $tid = eval { "[".threads->self->tid."]" }; + $tid = eval { "[".threads->tid."]" }; } # Check for whether we should be running continuously or not. @@ -4660,7 +4660,7 @@ sub cmd_e { print "threads not loaded($ENV{PERL5DB_THREADED}) please run the debugger with PERL5DB_THREADED=1 set in the environment\n"; } else { - my $tid = threads->self->tid; + my $tid = threads->tid; print "thread id: $tid\n"; } } ## end sub cmd_e @@ -4682,7 +4682,7 @@ sub cmd_E { print "threads not loaded($ENV{PERL5DB_THREADED}) please run the debugger with PERL5DB_THREADED=1 set in the environment\n"; } else { - my $tid = threads->self->tid; + my $tid = threads->tid; print "thread ids: ".join(', ', map { ($tid == $_->tid ? '<'.$_->tid.'>' : $_->tid) } threads->list )."\n"; diff --git a/pod/perlapi.pod b/pod/perlapi.pod index b868794..4ebc353 100644 --- a/pod/perlapi.pod +++ b/pod/perlapi.pod @@ -610,7 +610,7 @@ without it we only clone the data and zero the stacks, with it we copy the stacks and the new perl interpreter is ready to run at the exact same point as the previous one. The pseudo-fork code uses COPY_STACKS while the -threads->new doesn't. +threads->create doesn't. CLONEf_KEEP_PTR_TABLE perl_clone keeps a ptr_table with the pointer of the old diff --git a/pod/perlxs.pod b/pod/perlxs.pod index 6d14bae..61e023f 100644 --- a/pod/perlxs.pod +++ b/pod/perlxs.pod @@ -2007,7 +2007,7 @@ comma, i.e. C<_aMY_CXT>, C, C<_pMY_CXT> and C. =item MY_CXT_CLONE By default, when a new interpreter is created as a copy of an existing one -(eg via C<new()>>), both interpreters share the same physical +(eg via C<create()>>), both interpreters share the same physical my_cxt_t structure. Calling C (typically via the package's C function), causes a byte-for-byte copy of the structure to be taken, and any future dMY_CXT will cause the copy to be accessed instead. diff --git a/sv.c b/sv.c index 769922a..38d7da7 100644 --- a/sv.c +++ b/sv.c @@ -10709,7 +10709,7 @@ without it we only clone the data and zero the stacks, with it we copy the stacks and the new perl interpreter is ready to run at the exact same point as the previous one. The pseudo-fork code uses COPY_STACKS while the -threads->new doesn't. +threads->create doesn't. CLONEf_KEEP_PTR_TABLE perl_clone keeps a ptr_table with the pointer of the old diff --git a/t/op/threads.t b/t/op/threads.t index 43f6b07..f2b6df2 100644 --- a/t/op/threads.t +++ b/t/op/threads.t @@ -26,7 +26,7 @@ use threads; # Attempt to free unreferenced scalar: SV 0x40173f3c fresh_perl_is(<<'EOI', 'ok', { }, 'delete() under threads'); use threads; -threads->new(sub { my %h=(1,2); delete $h{1}})->join for 1..2; +threads->create(sub { my %h=(1,2); delete $h{1}})->join for 1..2; print "ok"; EOI @@ -40,7 +40,7 @@ my $data = "a"; my $obj = \$data; my $copy = $obj; Scalar::Util::weaken($copy); -threads->new(sub { 1 })->join for (1..1); +threads->create(sub { 1 })->join for (1..1); print "ok"; EOI @@ -57,7 +57,7 @@ use Scalar::Util qw(weaken); my $object = Foo->new; my $ref = $object; weaken $ref; -threads->new(sub { $ref = $object } )->join; # $ref = $object causes problems +threads->create(sub { $ref = $object } )->join; # $ref = $object causes problems print "ok"; EOI @@ -83,7 +83,7 @@ sub do_sort_threads { my $nthreads = shift; my @kids = (); for my $i (1..$nthreads) { - my $t = threads->new(\&do_sort_one_thread, $i); + my $t = threads->create(\&do_sort_one_thread, $i); print "# parent $$: continue\n"; push(@kids, $t); }