Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Can we write multi-threaded scripts ?

by dasgar (Priest)
on Nov 05, 2018 at 17:31 UTC ( #1225280=note: print w/replies, xml ) Need Help??


in reply to Can we write multi-threaded scripts ?

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).

  • Comment on Re: Can we write multi-threaded scripts ?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2021-01-27 16:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?