> If you want to try it yourself and report back, I'm sure we'd all be
> interested in what you find out. The main thing I'm aware of is that
> copy-on-write works very well for preforking and threads usually can't
> match it, but maybe your application is different.
> 
> Regarding your thread-safety questions, chdir() is global to the process,
> so not thread-safe. I think the issue with readdir() is that open directory
> handles don't get copied when threads are spawned, but maybe there's more
> to it. The special Perl vars are not a problem with threads, since each
> thread is a separate interpreter.
> 
> You can read about the limitations of threads here:
> http://perldoc.perl.org/threads.html#BUGS-AND-LIMITATIONS

File handles, directory handles, cwd, uid, euid, gid, egid, signal 
mask (%SIG): anything defined in the process struct is shared among 
all threads. For example, the BSD proc sturuct looks like:

<http://people.freebsd.org/~meganm/data/tutorials/ddwg/ddwg63.html>

which gives a rough idea of what is in common.

The only thing you can do with threads that forks make difficult is 
having multiple streams of execution working on a common data 
structure in parallel with about-to-block threads returning control
before they actually do block. Nice for a web server or database, but
you probably aren't writing an RDBMS in Perl :-)

By the time your computing problem has percolated up to the level of
Perl (vs. C) you are probably better off dealing with the work using
forks (at least on *NIX) in order to avoid all of the locking, memory,
and pool-manglement issues. 

-- 
Steven Lembark                                             3646 Flora Pl
Workhorse Computing                                   St Louis, MO 63110
lemb...@wrkhors.com                                      +1 888 359 3508

Reply via email to