[Chicago-talk] Speaking of threading

Steven Lembark lembark at wrkhors.com
Fri Dec 5 17:49:15 CST 2003



-- Greg Fast <gdf at speakeasy.net>

> So, speaking of threading...
>
> Does anyone have any practical experience with threaded 5.8?  The
> general reaction I've gotten from most folk I've talked to has been
> "perl threads are scary and I don't want to compile my own perl".

Ask the same people if they drive on the highway. You've
got much better odds of getting killed walking across the
street :-)

q.e.d., the unknown is always more frightening than reality.

> Are perl threads still scary?  I think the most scary parts (used to)
> be that threads made things slower, sneaky unspecified sharing danger
> deep inside perl, and non-core but common modules which are
> non-threadsafe (and also a lack of a good way to tell if a given
> module is threadsafe).  I think the first is solved and the second
> more or less resolved, but have no idea on the third.

The speed difference won't be notable in most cases. Today's
machines spend so much time blocking on I/O, bus access, and
DMA transferrs that the threading overhad probably doesn't
make that much difference.

> Is it reasonable yet to assume that an app with a "use threads" can be
> run by most people running 5.8?  It looks like RedHat 8 ships with a
> ithreads-happy perl (though RH8's perl is flaky in other ways), but
> the default configure options still reccommend no thread support.
>
> Any opinions?

The threading model in 5.8 is the sanest version of any
threading I've seen in any language. Basically, all lexicals
are local to the thread -- no sync required since they are
thread local -- most package variables are copied into the
thread's address space -- no sync required here either. The
stuff you really do want to share is marked as being shared,
sanity checked for data types, and has semaphores on it.

This avoids most of the mess you get with other languages
since the majority of what you want private is private to
begin with. There is an overhead copying globals, but you
can reasonably control that in most cases, and the few things
that are shared you know about becuase you marked them that
way.

If you use lexicals for most of your storage most of the
time then you may not even have any performance penalty or
major code modifications to threadify the stuff.

The perlthrtut describes this (double check me on the name).



--
Steven Lembark                               2930 W. Palmer
Workhorse Computing                       Chicago, IL 60647
                                            +1 888 359 3508



More information about the Chicago-talk mailing list