Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Note: I have posted this a meditation, since the question is rhetorical.

Yesterday, I asked for some help on the Chatterbox, building an ithreaded perl 5.8.0 on Solaris (which I still have not achieved). This prompted a response from merlyn, of the form "threads, threads, threads... Why is everyone obsessed with threads?"

There followed dscussion on the CB on the merits of threading and forks. I attended a London Perl Mongers meeting last night, and discussed the subject some more over beers.

The subject has been raised many times before on SoPW:
Thread vs. Fork
Threads vs Forking (Java vs Perl)
Threads, Forks, or Nothing?
Multithread / Fork Perl Examples.
To thread or not to thread
Status and usefulness of ithreads in 5.8.0
ActiveState, threaded fork and re-entrancy

My conclusion is that it really depends on exactly what you are trying to achieve in the multitasking. If the tasks are completely separate, they would benefit from separate address space, hence fork. Unfortunately on Windows, you haven't got a real fork, so perl does the best it can under the circumstances.

If what you want is cooperating tasks with much communication, such as shared memory structures, threads are a better model. The ithreads mechanism provides all the primitives to achieve locking etc. using method calls. Child processes can talk to each other, but you need to use an IPC mechanism such as pipes.


In reply to Threads versus fork, which to use? by rinceWind

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2024-04-19 06:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found