Hi Terry,

On Monday 07 Feb 2011 02:32:49 terry peng wrote:
> Sun, 06 Feb 2011 16:21:58 +0100 письмо от "Dr.Ruud" 
<[email protected]>:
> > On 2011-02-06 12:12, terry peng wrote:
> > > What's the suggested module for perl's threads?
> > > I have been using Perl 5.12 under linux.
> > 
> > Stay away from threads. Design and develop in a way that no internal
> > resources (but read-only data) are shared.
> 
> why no threads?
> I have been using threads in other language (like Java) for long time, I
> was thinking it's good.
> 

Well, let me quote the perlbot ( on Freenode's #perl ) factoid:

[quote]

<perlbot>       Before you start implementing code using Perl's threads, 
please remember that Perl's threads are not like other threads. Please see 
http://perldoc.perl.org/perlthrtut.html to learn more; specifically the "What 
kind of threads are perl threads?" section. Also see: 
http://www.perlmonks.org/index.pl?node_id=288022

[/quote]

Read these two resources and be enlightened. Threads do not work too well in 
any of the P-languages, and I was told that threads in Python with its 
notorious Great-Interpreter-Lock (GIL) suck - not "as bad as Perl" but still 
pretty badly. I haven't tried threads in Lisp yet.

Threads work pretty well in C, though they are extremely tricky to get right 
for non-trivial programs, and they should be pretty OK in .NET too (and again 
- quite tricky). Java and C++ may support threads nicely, but from what I 
heard and know developing in them is painful and error-prone in itself. See 
for example:

http://lbrandy.com/blog/2010/03/never-trust-a-programmer-who-says-he-knows-c/

("-c" there is "C++").

Some people say threads work very well in languages such as Erlang (where 
threads are "green threads" and are also used as a kind of cheap abstraction, 
and one can often spawn thousands of them on a machine with much fewer cores 
or processors), Haskell and other purely functional languages, but I don't 
know about that.

In any case, if you want to do multi-tasking in Perl, you should something 
like either forking and multi-processing or the recommendations here such as 
POE, Net::Async, IO::Lambda, Reflex, AnyEvent, etc:

http://perl-begin.org/uses/multitasking/

Some people think that threads should be avoided even in languages where they 
have acceptable performance. See for example:

http://www.faqs.org/docs/artu/ch07s03.html#id2923889

Furthermore, in regards to parallelism, in the Algorithm Design Manual 
( http://www.algorist.com/ ) says something that it is a good idea to split 
the task in such ways that processing every task is self-contained and 
requires as little interaction from the other tasks (IIRC).

Personally, I've done some simple multi-threading projects, but can imagine 
that more complex ones will be much more error-prone and hard to get right.

Regards,

        Shlomi Fish

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Chuck Norris/etc. Facts - http://www.shlomifish.org/humour/bits/facts/

Chuck Norris can make the statement "This statement is false" a true one.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/


Reply via email to