[CVALE] Threads on Linux
Landon Blake
lblake at ksninc.com
Wed Jun 28 13:08:48 PDT 2006
Thanks Pandora. I will check out those links.
I don't do any programming in Perl, (yet...), so there messed up thread
model shouldn't be a problem. I appreciate the warning though.
I'm trying to figure out how I can provide threads in that little
programming language I'm cooking up. I need to get a firm handle on how
threads work on Linux, and both of my Linux programming books didn't
mention them in the table of contents. I'm sure your links will help.
Landon
-----Original Message-----
From: cvale-bounces at lists.fire2wire.com
[mailto:cvale-bounces at lists.fire2wire.com] On Behalf Of Pandora
Sent: Wednesday, June 28, 2006 1:05 PM
To: cvale at cvale.org
Subject: Re: [CVALE] Threads on Linux
On Wed, 28 Jun 2006 11:58:18 -0700
"Landon Blake" <lblake at ksninc.com> wrote:
> I am looking for some information about programming with threads on
> Linux. I'm particularly looking for information on threads implemented
> in the c programming language on Linux. Also, I'd like to learn some
> more about the difference between threads and processes. I did some
> searching online, and read a couple of articles, but I was hoping you
> guys might have some other sources of information I could check out.
Sure, I've done a lot of threaded programming before. Let me see what
bookmarks I can pull up.
The LLNL has thankfully vastly improved their threads tutorial over the
years:
http://www.llnl.gov/computing/tutorials/pthreads/
Here's some talk of the recent revolutionary development among Linux
threads, that still works exactly the same way as before so you prolly
don't need to read this:
http://kerneltrap.org/node/422
Before you go and use threads, make sure you aren't doing something that
would be better handled by event based programming:
http://en.wikipedia.org/wiki/Event-driven_programming
Many threaded applications waste a lot of time locking and
synchronizing, when they could have just lined up the thread events
synchronously as event events. Even when simultaneity is desired, as
with multiprocessor environments, usually it's best to use an
event-driven programming loop combined with a thread pool:
http://en.wikipedia.org/wiki/Thread_pool_pattern
Also don't necessarily discount the versatility of the good old fork()
command, because it's supremely portable (except in Microsoft) and if
you only have to fork very rarely such as in the prefork model Apache
does by default:
http://httpd.apache.org/docs/2.0/mod/prefork.html
..it hardly produces any processing overhead at all compared to
threads, since it only forks once, then reuses the forked process as
HTTP requests come in. Preforking and thread pools are just about
identical matter of fact.
Oh one final thing. Never use threading in perl. Perl SCREWED UP their
threading system. They have no soft threading model, nor even a hard
threading model, in fact their threads are more expensive to produce
than their forks since they decided to make it so that every variable in
memory will be cloned and duplicated every time a new thread is created.
The only time threading in perl is in any way possible is if you create
all your threads at the beginning before any variables are declared, and
in that case one might as well use prefork processing.
Warning: anyone can copy this email as it is public domain and not
protected by any Orwellian laws. Everybody is allowed to disseminate,
distribute it, and copy it, including the original author.
--
Pandora "Starling/Tasci/Antinomy/Figment/???" synx
jabber: http://synx.dyndns.org/jabber.png
_______________________________________________
cvale mailing list
cvale at lists.fire2wire.com
http://lists.fire2wire.com/mailman/listinfo.cgi/cvale
Warning:
Information provided via electronic media is not guaranteed against defects including translation and transmission errors. If the reader is not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this information in error, please notify the sender immediately.
More information about the cvale
mailing list