Use newer 'threads' constructs
Jerry D. Hedden [Mon, 12 Feb 2007 12:04:33 +0000 (04:04 -0800)]
From: "Jerry D. Hedden" <jdhedden@yahoo.com>
Message-ID: <844555.64815.qm@web30202.mail.mud.yahoo.com>

p4raw-id: //depot/perl@30310

ext/XS/APItest/t/my_cxt.t
ext/threads/shared/t/blessed.t
ext/threads/shared/t/cond.t
ext/threads/shared/t/hv_refs.t
ext/threads/threads.xs
lib/Thread/Queue.t
lib/perl5db.pl
pod/perlapi.pod
pod/perlxs.pod
sv.c
t/op/threads.t

index 0b1c371..2c34794 100644 (file)
@@ -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");
index 157bb53..9938ad0 100644 (file)
@@ -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';
index 08b2d30..7f18950 100644 (file)
@@ -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;
index 938f7a7..cc57a34 100644 (file)
@@ -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");
index eb96414..1662ee8 100755 (executable)
@@ -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;
 
index 33c420b..b0d8c0a 100644 (file)
@@ -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++) {
index 1b9f376..9f5d3b1 100644 (file)
@@ -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"; 
index b868794..4ebc353 100644 (file)
@@ -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
index 6d14bae..61e023f 100644 (file)
@@ -2007,7 +2007,7 @@ comma, i.e.  C<_aMY_CXT>, C<aMY_CXT_>, C<_pMY_CXT> and C<pMY_CXT_>.
 =item MY_CXT_CLONE
 
 By default, when a new interpreter is created as a copy of an existing one
-(eg via C<<threads->new()>>), both interpreters share the same physical
+(eg via C<<threads->create()>>), both interpreters share the same physical
 my_cxt_t structure. Calling C<MY_CXT_CLONE> (typically via the package's
 C<CLONE()> 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 (file)
--- 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
index 43f6b07..f2b6df2 100644 (file)
@@ -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);
    }