Hi perl guru....

I'm new to thread in perl and during my exercise I experiment a problem
retrieving data from a child thread.

Using the world famous tecnique of cut & paste, I get some piece of code
from docs and I'v "build" a full script. 
This script is pasted at the bottom, and work ok from thread poit of view.
The problem happen when I try to retrieve the content of the 
array build inside the thread subroutine. The print statament inside the sub
show the content of the array and it is ok for every thread.
The subsequent print statement outside the sub code, give me strange values
and not what I expect, in other words what is wrong in my 
code ?

I'v also tried to submit the sample code find in HTML docs perlthrtut -
tutorial on threads in Perl section "Waiting For A Thread To Exit" 
with the same result.
Someone know wher is my error/misunderstanding.
Many tanks for attention, best regards and Happy new perl-year
Gianvy
(sorry for my poor english, I understand your difficult task, decode my mail
and after understand my problem, tankyou again)

Screenshot of the sample code
======================
D:\CONTAINER>perl
use threads;    
$thr = threads->new(\&sub1);   
 @ReturnData = $thr->join;
    print "Thread returned @ReturnData";    sub sub1 { return "Fifty-six",
"foo", 2; }
^Z
Thread returned 2



My script
====================================
use threads; 
use threads::shared;
   
sub loop {

    threads->yield;
    my $thread = shift
    my $foo = 5;
    while($foo--) { 
        $temp="in thread $thread";
        @Rdt=(@Rdt,$temp);
    }
    print "@Rdt\n";
    return @Rdt;
}

$thread1 = threads->new(\&loop, 'A');
$thread2 = threads->new(\&loop, 'B');
$thread3 = threads->new(\&loop, 'C');
$thread4 = threads->new(\&loop, 'D');
$thread5 = threads->new(\&loop, 'E');
$thread6 = threads->new(\&loop, 'F');

@Rdt1=$thread1->join;
@Rdt2=$thread2->join;
@Rdt3=$thread3->join;
@Rdt4=$thread4->join;
@Rdt5=$thread5->join;
@Rdt6=$thread6->join;

print
("Data1\n@Rdt1\nData2\n@Rdt2\nData3\n@Rdt3\nData4\n@Rdt4\nData5\n@Rdt5\nData
6\n@Rdt6\n");


=======================

My script output (only the section regarding the last print statement,
previous statement output a lot of data and is OK)

Data1
10
Data2
10
Data3
10
Data4
10
Data5
10
Data6
10


_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to