multithreading - perl threading problem -
I am writing a multithreaded website uptime checker in Perl, and even the basic code is still up to now (Threading only In section):
#! Use / Usr / bin / perl LWP :: UserAgent; Getopt :: Use Std; Use threads; Use thread: share; My $ Max: Share = 50; My $ Thread: Share = 0; Print "Website Uptime Checker \ n"; My $ infilename = $ ARGV [0]; Chomp ($ infilename); Open (INFILE, $ infilename); My $ outfill = $ ARGV [1]; Chomp ($ outfilename); Open (OUTFILE, "& gt;" $. $ Outfilename); OUTFILE- & gt; Autoflush (1); While ($ site = & lt; INFILE & gt;) {chomp ($ site); While (1) {if ($ Threads <$ maxthreads) {$ Threads ++; My $ thr = thread- & gt; Create (& amp; check_site, $ site); $ Thr- & gt; Apart (); last; } And {SO (1); }}} While ($ threads gt; 0) {sleep (1); } Sub-check_site {$ server = $ _ [0]; Print "$ server \ n"; $ Threads--; }
This returns an error after a while:
Do not call the "different" method on an unscheduled value on C: \ Pail \ WebShore can do. Pl line 28, line 245.
What is the reason for this error? I know this is different, but what am I doing wrong in my code? Windows shows lots of memory, so the computer should not be out of memory, this error occurs when I can also set $ max or $ maxthreads as low as possible.
The specific problem is that thread-> create
failed to create a thread And so it's undef
. Call detach
before calling thr
, if you want your code to be stronger
Comments
Post a Comment