Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Multithreading

by Masem (Monsignor)
on Jul 20, 2001 at 17:23 UTC ( [id://98398]=note: print w/replies, xml ) Need Help??


in reply to Multithreading

You probably want to use the fork function, which basically creates a child process using the same perl code. There's more details on the perldoc pages as well as here on PM, but the general idea is that your parent process can create however many instances it needs and wait for them to finish via waitpid. The children should write data to files, which the parent process can then collate and put into the final HTML file(s) that you want.

-----------------------------------------------------
Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain

Replies are listed 'Best First'.
Re: Re: Multithreading
by c-era (Curate) on Jul 20, 2001 at 18:09 UTC
    What works even better, is to have the children write to one file, but use an excluse lock. Then the parent can sort the file if you need to.

    Another option, is to have the children write back to the parent.

    my $pid = open ($handle, "-|"); if ($pid){ my $return = <$handle>; close $handle; # Do something with the return value } else { # Do something interesting print $handle "Something interesting"; close $handle; exit; }
    Note, I'm on a windows box so I wasn't able to test the above code, but it should be close. Now for mulitple children you'll need to use IO::Select.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (6)
As of 2024-04-16 07:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found