Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^4: thread::share problem

by Anonymous Monk
on May 13, 2012 at 01:45 UTC ( [id://970227]=note: print w/replies, xml ) Need Help??


in reply to Re^3: thread::share problem
in thread thread::share problem

Ok here's my advanced demo codes

# use strict; # use warnings; use Win32::GUI; use LWP::UserAgent; use HTML::TagParser; use WWW::Mechanize; use URI; use Win32::PingICMP; use threads; use Thread; use Thread::Cancel; use threads::shared; use Data::Dumper; use Thread::Pool::Simple; my (@REVERSESITES, @URLPOOL_th,@URLPOOL_ty); share(@REVERSESITES); # share(@URLPOOL_th); # share(@URLPOOL_ty); my $ua = LWP::UserAgent->new(); $ua->timeout(5); my $agent = WWW::Mechanize->new( 'autocheck' => 1, timeout => 5,'onerr +or' => undef, ); my $p = Win32::PingICMP->new(); # threads->yield(); $ua->agent('Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; InfoPat +h.2; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; +.NET CLR 1.1.4322)'); # ------------------------ # GUI AREA # ------------------------ Win32::GUI::Dialog(); sub Win_Terminate {return -1;} sub Button_taramabasla_Click { # START BUTTON PRESSED threads->create(\&asama1); } sub Button_LOAD_Click { # blah blah } sub asama1 { # SECTION 1 (..) # if else blocks push(@GENERALURLPOOL, $result); (..) &asama2(); } sub asama2 { my $google = scalar @GENERALURLPOOL; $Progress_bars->SetRange(0,$google); foreach my $urls (@GENERALURLPOOL) { $Progress_bars->SetStep(1); $Progress_bars->StepIt(); # GETTING RESULTS # parsing all urls and results adding to @GENERALURLPOOL_2 (..) push(@GENERALURLPOOL_2,$urls); (..) } $Progress_bars->SetRange(0,0); $Progress_bars->StepIt(); $Win->RichEdit_1->Append("finished.\r\n"); &asama3(); } sub asama3 { $getsinir = scalar @GENERALURLPOOL_2; $Progress_bars->SetRange(0,$getsinir); foreach $geturl (@GENERALURLPOOL_2){ # parsing urls and results adding to @IPPOOL (..) push (@IPPOOL, $ips); (..) } $Progress_bars->SetRange(0,0); $Progress_bars->StepIt(); $getsinir2 = scalar @IPPOOL; $Progress_bars->SetRange(0,$getsinir2); $Win->RichEdit_1->Append("finished.\r\n"); &GETSHIT(); } sub GETSHIT { sub workder { $ips = shift; # @REVERSESITES shared # lock(@REVERSESITES); Before writing such not printing array elements + in "asama4" subroutine lock(@REVERSESITES); # progress starting (...) if(defined($numbers) || $numbers <=50){ $Win->RichEdit_1->Append("Please wait...\r\n"); while(<while>){ # if else blocks push (@REVERSESITES,$1); } } $Progress_bars->SetStep(1); $Progress_bars->StepIt(); } my $pool2 = Thread::Pool::Simple->new( min => 3, max => 20, do => [\&workder] ); for(@IPPOOL) { $pool2->add($_); } $pool2->join(); $Win->RichEdit_1->Append("Finished.\r\n"); &asama4(); } # OK the problem starts here # 3 problems # -Scalars Leaked : 18 (this is not a big problem) # -Can't call method "STORE" on an undefined # -panic: COND_DESTROY (6). sub asama4 { # ok i'm getting and printing of the array (@REVERSESITES) elements , +lock() is working print $_,"\n" for @REVERSESITES; $getnumm = scalar @REVERSESITES; $Progress_bars->SetRange(0,$getnumm); sub workerss { my $urladdr = shift; $Progress_bars->SetStep(1); $Progress_bars->StepIt(); $ua->get($urladdr); if($ua->content =~ m/content/ig){ push (@URLPOOL, $urladdr); } } use Thread::Pool::Simple; my $pool = Thread::Pool::Simple->new( min => 3, max => 20, do => [\&workerss] ); for(@REVERSESITES){ $pool->add($_); } $pool->join(); $Win->RichEdit_1->Append("Finished.\r\n"); $Progress_bars->SetRange(0,0); $Progress_bars->SetStep(1); # there is big problem @URLPOOL array not printing # lock() function not working, returning with error; "panic: COND_DES +TROY (6)." or "Can't call method "STORE" on an undefined" or just lea +ving the program without errors. print $_,"\n" for @URLPOOL; &asama5(); } # sub test { print "s\n";} sub asama5 { # there is big problem @URLPOOL array not printing print $_,"\n" for @URLPOOL; (....) } sub Button_deletelements_Click {$pass->DeleteAllItems();} sub error { Win32::GUI::MessageBox(0, shift, "Error", 64|0); }

Replies are listed 'Best First'.
Re^5: thread::share problem
by BrowserUk (Patriarch) on May 13, 2012 at 08:26 UTC

    Okay. The almost certain cause of the panic:COND_DESTROY message is because you are defining thread functions inside other functions. Here:

    sub GETSHIT { sub workder { $ips = shift; ...

    And here:

    sub asama4 { # ok i'm getting and printing of the array (@REVERSESITES) element +s , lock() is working print $_,"\n" for @REVERSESITES; $getnumm = scalar @REVERSESITES; $Progress_bars->SetRange(0,$getnumm); sub workerss { my $urladdr = shift; ...

    But, your code is so badly written and formatted that I am not prepared to expend any energies on trying to fix it.

    My advice to you is that you should either: a) start with a simpler project and learn to write clean, structured code before you attempt something as complex as this; or b) employ a proper programmer to write this for you.

    Have you ever watched one of the TV game-shows where they bring in an expert pizza maker or master potter or similar, and have them demonstrate their skills for about 2 minutes; before asking one or more of their victims contestants to try and replicate what the expert did?

    Of course, as expected, the contestants end up covered in pizza dough/wet clay and offer up an unrecognisable pile of something for the expert to judge. In this context, your posted code is that unrecognisable pile of something. Sorry if that is harsh, but not everyone is cut out to be a programmer.

    If you posted a new version that was properly indented and compiled with strict & warnings, I might take another look, but as is:

    I'm not prepared to expend any more of my time on it.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

      Thank you very very much browseruk realy thank you, i respect you.

      a) ok i will (realy thank you for this)

      b) No no no i'm good programmer! I trust myself. Actually i'm starting programming in 2007 with perl!. And write big projects, so -20.000 , 30.000- lines of a few projects, but these days i'm so so tired.I'm learning c#, php, mysql, html, css

      "Have you ever ..." and "Sorry if that is..."

      No on the contrary, i'm glad for your said. Just i did not read enough documents! Maybe that's the BIG problem.

      Ok no problem, i just wanted a few tips.Thank you very much again thank you for taking the time.

      Regards.

      Thank you.

Re^5: thread::share problem
by merlol (Initiate) on May 13, 2012 at 02:03 UTC

    Do you have other methods about of multithreading?

    I'm used before "Thread" module for multithreading for controlling running threads, but Active State Perl Dev Kit so, "perlapp" cannot compile my project and getting same errors. Like this ; "Undefined ... &Thread::threads::running" and program stopping.

    Therefore i'm using "Thread::Pool::Simple".

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://970227]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-19 13:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found