Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Personally, I hate the "discouraged" label being applied to threads - especially considering the official definition of "discouraged" in the perldocs. The wording of that definition leaves a distinct impression that threads are just a step or two away from being removed from Perl, which becomes a heavy handed scare tactic.

When I first started looking at doing things in parallel, I looked at forks and threads. For some reason, I couldn't get my head wrapped around how to use forks, but I had no trouble with understanding threads. So I started using threads. Some time later, I found documentation (fork in perlport and perlfork) that indicated that Perl will emulate fork using threads in Windows. Since I happen to mainly work in Windows, that means ultimately I will be using threads no matter what I choose between threads or fork.

In my opinion, using threads in Perl code can be ok. However, you do need to keep some things in mind as you do so. This isn't an exhaustive list, but some items that I can think of are:

  • Not all modules are thread safe. And a large number of modules (possibly most) will not include anything in their documentation to indicate if it is thread safe or not.
  • Portability: If a Perl installation was not compiled to support threads, then your code won't work in that Perl installation.
  • Support: You might have a hard time finding help. And in many forums, you might receive harsh responses about using threads.

Personally, I'm not going to try to persuade anyone to use or not to use threads in their Perl code. Instead, I would say try to educate yourself so that you can make an informed decision about your choice to use or not to use threads. In my case, I initially made an uninformed decision and later learned enough information to be able to make an informed decision to continue using threads (at least for now).

In reply to Re: Can we write multi-threaded scripts ? by dasgar
in thread Can we write multi-threaded scripts ? by toughy

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?

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-20 04:51 GMT
Find Nodes?
    Voting Booth?

    No recent polls found