I try to use Thread::Queue to send info, but when join this thread, it leads to a error " Free to wrong Pool", I followed some topics about this error, cannot find any reasonable explanation, except for use of win32::ole
our @Task_list; our ($DataQueue1,$DataQueue2); my $ExcelFile='D:\HF_project_perl\Update.xls'; #this use win32:ole to read excel @Task_list=Create_TaskList($ExcelFile); print "Create TaskList"; #Create 2 Queues $DataQueue1-- Main thread to thread1; #$DataQueue2-- +-therad1 to thread2 $DataQueue1 = Thread::Queue->new(); $DataQueue2 = Thread::Queue->new(); my $thr1 = threads->create(\&thread1); print "set up thread1 \n";#for debug my $thr2 = threads->create(\&thread2); print "set up thread2 \n"; #for debug #Assign Task to thread1 by $DataQueue1 for my $i (0..$#Task_list){ $DataQueue1->enqueue($Task_list[$i]); print "send task $i to Thread1 \n"; #for debug print "wait 10s \n"; sleep(10); } #Task completed Flag $DataQueue1->enqueue(undef); print "send undef to stop T1 "; $thr2->join(); $thr1->join(); sub thread1{ my $TaskRef; my $Taskcounter; while ( defined($TaskRef = $DataQueue1->dequeue())) { $Taskcounter++; my $SecID=$TaskRef->{SecID}; my $Date=$TaskRef->{Date}; print "Thread1 finish task $Taskcounter"; print "$SecID $Date \n"; $DataQueue2->enqueue($TaskRef); # notify thread2 to follow the task, Assign Task to thead2 by $DataQue +ue2 print "Send task $Taskcounter to T2 \n";#for debug print "T1 wait 2s \n"; sleep(2); } $DataQueue2->enqueue(undef);#Task completed Flag select(STDOUT); print "T1 stop and inform T2 to stop \n"; #for debug } sub thread2{ my $TaskRef; my $Task_Finished_counter=0; while ( defined($TaskRef = $DataQueue2->dequeue()) ) { print "Thread2 finish task $Task_Finished_counter"; print "$TaskRef->{SecID} $TaskRef->{Date} \n"; #for debug } print "T2 stop \n"; #for debug }
a easy example for threads way, error "Free to wrong Pool" happens when join the thread , why ?

In reply to Re^2: send info between 2 programs by jiwei800715
in thread send info between 2 programs by jiwei800715

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.