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

Hello, monks!

1) Can you please point me to some good article describing pros and cons of using forks and threads?

2) How do I create two-dimensional (or, well, multidimensional) array or hash using threads and strict? Strangely, I can't do this myself O_o

Replies are listed 'Best First'.
Re: Threads, forks and stuff?
by moritz (Cardinal) on Sep 10, 2008 at 16:32 UTC
      Thanks! I will read it.
Re: Threads, forks and stuff?
by Joost (Canon) on Sep 10, 2008 at 23:18 UTC
    1) see above, but the short answer is: fork is much more efficient in general at least on any UNIXy system, but threads make it slightly easier to share data. update: note that much of this is because of the way Perl handles threads: in some other languages, threads are much more efficient, and usually make sharing easy to the point of making correct behaviour hard to code.

    2) Just using threads has no impact on your ability to create multi-dimensional data structures. Sharing those structures between threads may be a little complex. See threads::shared. Using strict may impact your ability to create multi-dimensional datastructures, but usually, that means you're doing it wrongtm:

    use strict; use threads; my $structure = [ 'a', 'b', 'c', { some => 'hash' }, [ 'some', 'array' + ]];

Re: Threads, forks and stuff?
by BrowserUk (Patriarch) on Sep 10, 2008 at 18:28 UTC
    2) How do I create two-dimensional (or, well, multidimensional) array or hash using threads and strict? Strangely, I can't do this myself

    How are you trying to do it? What errors are you getting?


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.