[linux-elitists] Threads vs. Processes [was Re: email elitims]

Shlomi Fish shlomif at iglu.org.il
Mon Sep 21 04:52:18 PDT 2009


On Monday 21 Sep 2009 13:11:04 Ben Finney wrote:
> Eugen Leitl <eugen at leitl.org> writes:
> > Emacs still doesn't do multithreading though, right?
> 
> Real elitists demand programs that subdivide their work with plain
> processes and narrowly-specified IPC. Processes are well-understood, and
> cheap on operating systems that matter. Threads are an evil hack for
> OSes that don't implement processes well.
> 

Another processes vs. threads war? OK, I'll bite.

Threads have their problems - probably more than processes do. But they are 
still a valid multi-tasking approach. Writing multi-threaded programs is not 
easy, but it's very easy to mess multi-processing apps too.

Some examples from my experience:

1. When my partner and I wrote http://ip-noise.berlios.de/ , we opted to use 
several threads for the IP-Noise-simulating server's version in user-land 
(written first in Perl and then in ANSI C). This server still runs very well 
on contemporary Linux systems, and I've heard from several people who 
successfully deployed it.

When we converted the code to run in kernel-land, we removed the use of the 
threads, and it also worked pretty well, but we did not test it on a multi-
processor machine because our computer lab did not have one (unfortunately). 
In later kernels, some compatibility was broken, and since we were sloppy due 
to ignorance, the kernel module version no longer works.

(The kernel anecdote is a little besides the point, but I wanted to share it.)

2. Much more recently, I decided to create a multi-threaded version of 
http://fc-solve.berlios.de/ (I see Mulix is preparing the grogers), that just 
used several instances of the solver to solve a range of boards in a round-
robin fashion. This version performed faster on the first 32,000 boards on my 
Pentium 4 machine with hyperthreading, and the speed increase was much more 
dramatic with a multi-core computer.

While I could have written it using several processes, I opted to use threads 
and POSIX threads instead out of convenience, and it worked very well. I 
conversed with someone who claimed he was an expert in designing concurrent 
algorithms and he said I should avoid locking as much as possible and use 
lock-free data-structures. However, when I implemented round-robin quotas of 
more than one board at a time (to reduce the locking) it did not make a huge 
difference.

-------------------

I should also note that I also think the multi-threaded version of Apache 2.x 
runs faster than the multi-processed version.

Maybe I'm not a true Linux elitist in the sense that I'm still trying to 
support other UNIXes beside GNU/Linux (both FOSS and non-FOSS), and even MS 
Windows if possible. For the record, porting to MS Windows is usually much 
easier than porting to VMS, which some Perl and CPAN authors are still doing 
because it is an important platform for them. And there may be even weirder 
OSes that one can still find in many places.

(The reason I'm still here is because I enjoy the conversations, however 
elitist they may be.)

Moreover, Linux is diverse enough that some distributions will run things 
properly while others won't (or the same for different architectures). If you 
don't want to get rid of 90% or so of your audience, you should make sure your 
program is portable outside your particular environment. 

I think one of the reasons many hardware vendors have started giving good 
support for Linux is not because it has so many users, but because these users 
are very influential. A common Aunt Tillie will probably need help and 
guidance from her cousin Joey even if she uses Windows, and this cousin Joey 
may very well be a Linux fan, and will probably recommend his Aunt to buy a 
computer that can run Linux. The market penetration of Linux is not very 
large, but we can assume that it is very influential on the market at large 
due to the average cluefulness of Linux people.

Similarly, many Linux users won't use a program which they cannot easily 
deploy on the Windows environments of theirs or their peers. (Including to a 
large extent me).

Like Francis Bacon said: "Reality to be conquered - must be obeyed.".

Regards,

	Shlomi Fish

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Freecell Solver - http://fc-solve.berlios.de/

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.


More information about the linux-elitists mailing list