Linux 螺纹连接问题

Linux 螺纹连接问题,linux,multithreading,perl,Linux,Multithreading,Perl,我在linux机器上使用Perl,我的内存使用率在不断上升,我相信这是因为以前运行的线程没有被终止/加入。 我想我需要以某种方式通知已经完成/运行的线程终止,然后分离 它/他们,这样它/他们会被自动清理,给我回记忆 我已经试过了;使用$thr_List->join();&$thr_列表->分离();但是我的gui在join上已经很久没有显示了,mem的问题似乎也出现了 我想和你在一起。。。任何帮助 $mw->repeat(100, sub { # shared var handler/pi

我在linux机器上使用Perl,我的内存使用率在不断上升,我相信这是因为以前运行的线程没有被终止/加入。 我想我需要以某种方式通知已经完成/运行的线程终止,然后分离 它/他们,这样它/他们会被自动清理,给我回记忆

我已经试过了;使用$thr_List->join();&$thr_列表->分离();但是我的gui在join上已经很久没有显示了,mem的问题似乎也出现了 我想和你在一起。。。任何帮助

$mw->repeat(100, sub { # shared var handler/pivoting-point !?

while (defined(my $command = $q->dequeue_nb())) { #???
# to update a statusbar's text
        $text->delete('0.0', "end");
        $text->insert('0.0', $command);
  $indicatorbar->value($val); # to update a ProgressBar's value to $val
  $mw->update();

    for ( @threadids ) { # @threadids is a shared array containing thread ids
    # that is to say I have got the info I wanted from a thread and pushed its id into the above @threadids array. 
    print "I want to now kill or join the thread with id:  $_\n";
        #$thrWithId->detach();
        #$thrWithId->join();
    # then delete that id from the array 
    # delete $threadids[elWithThatIdInIt];


    # as this seems to be in a repeat(100, sub... too, there are problems??!
    # locks maybe?!? 
    # for ( @threadids ) if its not empty?!?
        }
   } # end of while
}); # end of sub

# Some worker... that works with the above handler/piviot me thinks#???
async {
   for (;;) {
 sleep(0.1);
 $q->enqueue($StatusLabel);
   }
 }->detach();
我已经在这里上传了我的完整代码(http://cid-99cdb89630050fff.office.live.com/browse.aspx/.Public)如果需要,它可以放在长方体的.zip中


首先很抱歉在这里回复,但我丢失了允许编辑的cookie等

非常感谢gangabass,这看起来是一个很好的信息,虽然我必须花一些时间在上面,但至少看起来其他人也在问同样的问题。。。我担心我把事情搞得一团糟


谢谢各位…

听起来你们的加入工作正常,但速度很慢

perl中的线程不是轻量级的。创建和连接线程需要大量内存和时间。
如果您的任务允许,最好保持线程运行并为其提供额外的工作,而不是结束线程并稍后启动新线程。我能帮上忙。也就是说,除非您在Windows上,否则这样做并没有多大意义,而不是分叉和使用。

您只需要使用一个辅助线程,并从中更新GUI。其他线程只处理队列中的数据,不需要终止它们


参见示例了解更多信息

如果没有连接,我可以看到我的Gui更新(显示ping的内容和完成的百分比),但是有了连接,Gui直到所有事情都完成后才会显示…错误,连接将等待线程完成。这不是你想要的吗?线程在做什么?您希望它什么时候完成?