Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Re: Re: returning from a thread ?

by liz (Monsignor)
on Aug 21, 2003 at 14:07 UTC ( #285473=note: print w/replies, xml ) Need Help??


in reply to Re: Re: returning from a thread ?
in thread returning from a thread ?

Strange. Which version of Perl are you using on which platform? The main program should not block!

Liz

Replies are listed 'Best First'.
Re: Re: Re: Re: returning from a thread ?
by Foggy Bottoms (Monk) on Aug 21, 2003 at 14:15 UTC
    Here's my bit of code below :
    # now stop the current scan thread # to do this, write in a file th_com.thd the value 0 if (defined $thread) { open (THREADCOM, ">".LTG::dialog::THREADCOM) or die "Can't creat +e/overwrite file: $!\n"; print (THREADCOM,"0"); close THREADCOM; # stop thread } print "create thread\n"; $thread = threads->new(\&LTG::scanChange::monitor());# \&LTG::scanC +hange::monitor); $thread->detach(); # let go off the new thread
    And here's the sub's code
    sub monitor { my @wantedF; # folders to be scanned my @bannedF; # banned folders not to be scanned if ( -e LTG::dialog::CONFIGFILE) { open(FOLDERLIST,LTG::dialog::CONFIGFILE) or die "can't open file +"; my $content = <FOLDERLIST>; my $addForce = 0; while ($content) { if ($content ne "\n") { $content =~ s/\n/ /; ($content =~/^\#FORCE\#/)?($addForce = 1):(($content =~/^\# +BAN\#/)?($addForce = 0):($addForce?push(@wantedF,$content):push(@bann +edF,$content))); } $content = <FOLDERLIST>; } close (FOLDERLIST); } open (THREADCOM, ">".LTG::dialog::THREADCOM) or die "Can't create/o +verwrite file: $!\n"; print THREADCOM "1"; close THREADCOM; my $active = 1; while ($active) { if ( -e LTG::dialog::THREADCOM) { open(THREADCOM,LTG::dialog::THREADCOM) or die "can't open fil +e THREADCOM"; $active = <THREADCOM>; print "active : $active \n"; close THREADCOM; } my %changes = LTG::scanChange::startScan(\@wantedF,\@bannedF,INC +_SUBDIRS); foreach my $k (keys %changes) { print "key : $k -> content : $changes{$k}\n"; } # update database here Sumith # print "---while---\n"; } }
    I'm running perl on a Winnt 4.0 system, and here's my perl info (perl -v)
    This is perl, v5.6.1 built for MSWin32-x86-multi-thread (with 1 registered patch, see perl -V for more detail) Copyright 1987-2001, Larry Wall Binary build 635 provided by ActiveState Corp. http://www.ActiveState. +com Built 15:34:21 Feb 4 2003 Perl may be copied only under the terms of either the Artistic License + or the GNU General Public License, which may be found in the Perl 5 source ki +t. Complete documentation for Perl, including FAQ lists, should be found +on this system using `man perl' or `perldoc perl'. If you have access to + the Internet, point your browser at http://www.perl.com/, the Perl Home Pa +ge.
      This is perl, v5.6.1...

      This implies that you cannot using ithreads, but this:

      $thread = threads->new(\&LTG::scanChange::monitor());
      implies that you are. Officially, ithreads were not supported under 5.6.1, maybe they were available then already under the hood with Win32. Anyway, they're not guaranteed to work and therefore should not be relied upon. Please upgrade to 5.8.0 before trying to do anything with ithreads.

      Sorry to be the bringer of bad news in that respect.

      Liz

        Hi Liz, I've just installed Perl 5.8 :
        This is perl, v5.8.0 built for MSWin32-x86-multi-thread (with 1 registered patch, see perl -V for more detail) Copyright 1987-2002, Larry Wall Binary build 806 provided by ActiveState Corp. http://www.ActiveState. +com Built 00:45:44 Mar 31 2003 Perl may be copied only under the terms of either the Artistic License + or the GNU General Public License, which may be found in the Perl 5 source ki +t. Complete documentation for Perl, including FAQ lists, should be found +on this system using `man perl' or `perldoc perl'. If you have access to + the Internet, point your browser at http://www.perl.com/, the Perl Home Pa +ge.

        Unfortunately, my main file doesn't work fine anymore : I get this Dr. Watson error :
        Acces violation (0xc0000006) address : 0x026663ec1

        I'd forgotten how concise these messages were. It also did this on another file and I realized it was due to Win32::GUI which I reinstalled - I also reinstalled Win32::OLE. I wanted to install the package called threads, but there is no such thing - I'm getting quite confused. Have you any idea where the problem might be ?

        --- PROBLEM FIXED ---
        Hi Liz,

        It's me again... and back to square one - I fixed all my Perl 5.8 migration problems and am back on the thread problem. I've just tested it and it still doesn't return.

        What is the exact bit of code that tells the thread not to freeze the parent process ? If it is detach(), then if it comes after having created and started the thread, how can it possibly know ?

        This may be a dumb question, sorry for the inconvenience...

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2022-08-09 20:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?