Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Spawing several threads

by mecrazycoder (Sexton)
on Sep 04, 2009 at 12:33 UTC ( [id://793447]=perlquestion: print w/replies, xml ) Need Help??

mecrazycoder has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, I am having two Perl files say file1.pl and file2.pl.I want file1.pl to spawn 12 threads.This threads must invoke file2.pl.As i am not comfortable(so far) with thread, i cant understand things given in this forum/websites.So someone please help to walk me through the script. Tanx in advance

Replies are listed 'Best First'.
Re: Spawing several threads
by roboticus (Chancellor) on Sep 04, 2009 at 13:17 UTC
    mecrazycoder:

    Provide your first attempt at a script, and we'd be delighted to help you. Most of us aren't very interested in just doing your homework for you, though. Read up on threads (perldoc threads), give it a try, and see how far you can get. We'll help you when you get stuck.

    ...roboticus

      Also, start simple.

      First grab the example code from the docs, and get that running. Then you can slowly start making it spawn more kids, and have the children do gradually more interesting things until it has grown to the point where it is doing what you wanted in the OP.

      Of course, given the description, you might just want to use a batch file instead. Copy paste 12 lines of launching background perl interpreters, and you're done.

Re: Spawing several threads
by tbone1 (Monsignor) on Sep 04, 2009 at 13:52 UTC
    First show us the code you have so far. Second, would it be easier (if not necessarily better) to fork off child processes instead of using threads? Based on the nature of the problem and the code you have, we might tell you to fork off.

    Er, wait, let me rephrase that ...

    --
    tbone1, YAPS (Yet Another Perl Schlub)
    And remember, if he succeeds, so what.
    - Chick McGee

Re: Spawing several threads
by ig (Vicar) on Sep 04, 2009 at 23:29 UTC

    If all you want is 12 separate processes each running file2.pl then you don't need threads in file1.pl.

    I find that simple solutions are easier to write and maintain than more complex solutions. Therefore, I would not use threads in file1.pl unless there was a compelling reason for them. I suggest you think carefully about why you want to use threads. Maybe it's not necessary.

    If you explain why system and fork are inadequate for your needs, it will be easier to provide helpful suggestions.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2024-04-18 23:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found