Re: Threads question

Jean-Philippe Langlois (jpl@iname.com)
Fri, 25 Apr 1997 18:18:30 -0400


Larry McVoy wrote:
>
> : I often hear about how lightweighted linux processes and thus threads
> : (based on clone) are. However I have not heard of how many it can easily
> : handle, or even of a maximum number. More precisely, I am thinking of
> : designing a GUI library that could use one thread per window. It is safe
> : to say that an average application could have 100 windows, so that an
> : average system could easily have 1000 windows totalling 1000 threads.
> : Can the linux kernel cope with thousands of threads?
>
> A better question is "can your system cope with a 1000 threads?". It is
> sad but true that threads have been overhyped - not by the Linux folks,
> those threads are as good or better than any. You have a basic memory
> problem that others have independently discovered. Each thread needs a
> stack, which is probably at least a 4K page or more. That's 4mb of memory
> for just the stack, let alone any thread specific data.
>
> A choice between a window system that was threaded and 4mb bigger than
> a window system that used events would be an easy choice for many to make.
> Especially since threaded window systems don't work very well. Great for
> demos, crappy in real life.
>
> Think of it this way: threads are like salt, not like pasta. You like
> salt, I like salt, we all like salt. But we eat more pasta :-)
> Same breakdown for threads vs other programming models. Contrary to
> all the hype, threads != pasta.
>
> Not what you wanted to hear, I'm sorry to say.
>
> --lm

Please don't apologize. I should have said that my project was really a
research/curiosity project. The _real_ thing is actually designed with
two threads in the most common case. One to handle the GUI with events
dispatched sequentially, and one to do the rest of the work.
My curiosity came from the BeOS, which I heard uses one thread per
window. When asked about the overhead in memory and cpu time for
switching contexts, they told me their threads where _really_
lightweighted. But your remark made much sense, someone else also
mentioned 4MB os user stack as well. 8MB just for the threads' stacks
would be a ridiculous waste. Thanks for your input.

JPL.