I am really wondering why it was decided to make Linux's Kernel-space
threads seperate processes. I see the benchmark at the Linux Thread FAQ
site, ...
"Also the scheduler has been
optomized so that the switching time for threads vs. tasks varies
little--about 1.7us (threads) and 1.8us (fork) on a
75MHz Pentium."
This statement itself seems to give me the idea that this decision was a
bad one...I mean, if a thread in Lunix is actually a process, it is no
wonder that the 2 are very close in performance. This doesn't tell me
that Linux processes are fast, but perhaps Linux threads are slow.
In that same website is stated:
"Kernel-space threads often are implemented in the kernel using several
tables (each task gets a table of threads).
In this case, the kernel schedules each thread within the
timeslice of each process. "
granted, my knowlage of the workings of an OS is limited (to say the
least), but that does not sound like the description of a seperate
process to me,...even with shared memory. Why didn't they do it this
way?
Then, in a book on threads (PThreads Primer, available on the net,
though I forget were...) page 52....
"What about shared memory?
Right now you may be asking yourself this question: "What can threads do
that can't be done by processes ahring memory?"
The first answer is "nothing." Anything that you can do with threads,
you can do with processes ahring memory. Indeed, a number of vendors
implement a significant portion of thier threads library in roughly this
fashion. If you are thinking about using shared memory in this fashion,
you should make sure you have (a) plenty of time to kill programming,
(b) plenty more time to kill processing, and (c) plenty of money to burn
buying RAM.
You see: (a) debugging gross-process programs is tough, and the tools
that exist for this are not as good as the ones for MT. (b) Things take
longer. In Solaris, creating a process is about 30 times slower than
creating a thread, syncronization variables are about 10 times slower,
and contex switching about 5 times slower. (c) Processes eat up a lot
of kernel memory. Building a few thousand threads is no big deal.
Building a few thousand processes is.
You can do everything with shared memory. It just won't be as easy or
run as fast."
So, now I am wondering, with all the things above stated,...why was it
decided that a thread should be a new process? It sounds as though that
is one of those ugly "Well, it works" hacks. Though from the look of
what I have read, it probably doesn't work well...
Maybe some hard core benchmarking between Linux's kernel-space threads,
and those of other OSs would better illistrate how Linux threads are
"better". That is something I would definately like to see.