in reply to thread::share problem

You would be far more likely to get a solution if you posted runnable code that demonstrates the problem.


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?

Replies are listed 'Best First'.
Re^2: thread::share problem
by merlol (Initiate) on May 12, 2012 at 21:53 UTC

    Ok no problem of the code. I understand that I must use the lock() function.But what is this;

    Scalars leaked: 18 < this is no problem

    Scalars leaked: 18

    Scalars leaked: 18

    panic: COND_DESTROY (6). what is this?

    There are too many bugs in perl.

      panic: COND_DESTROY (6). what is this?

      It means that when perl came to destroy a condition var, when it attempted to close the handle to the associated semaphore, the handle was invalid.

      The usual cause of this is an attempt to destroy the condition var a second time.

      And the usual cause of that is programmer error.


      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?

        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); }