: Okay, I looked it up in an online dictionary and I sort of get it but
: can someone explain what multithreading is and why it matters
: (particularly for running a web server)? In responses to another
: question of mine I was told that the crucial difference between
: Solaris x86 and Linux was that Linux doesn't do multithreading. So
: before I plunk down $1,200 for Solaris x86, can someone enlighten me.
: Does multithreading happen automatically with a multithreading OS or
: do programs have to be written to take advantage of it? Or whatever?
: Please fill me in.
Reasons for making your web server multithreaded:
1. Less memory and processing overhead when handling multiple network
if you were to write a network server you would fork processes to
handle clients in parallel. An alternative is to create threads which has much
lesser overhead since the whole address space is not copied, but only some
things like stack, program counter and registers.
2. The communication between threads is much simpler compared to that
Communication is done largely through various global variables and
synchronised using mutexes.
3. The program can be easily be made more responsive that otherwise since
blocking calls block only the thread not the entire process.
If the app is one process and get blocked while accessing a resource the whole
process with block. On the other hand, in a multithreaded app, this resource
can be requested in a independent thread which can then set a flag
indicating the success. While that thread is blocked the main thread
can perhaps indicate to the user that the data is on the way.
So,figuratively speaking you can avoid a clock
showing up at the user interface under any circumstance !!!
4. You can achieve parallel execution (using multiple proceccors,
if available) to a very fine granularity easily, compared to achieving
the same using multiple processes.
In the case of your web server, you could have one main
thread initially. When three clients connect simultaneously then you could
have three client threads to service each of these requests. If any of
these requests require say a search of several files, you could spin off
independant threads to do them, while you wait for the completion and so on...
Regarding the other question.....
Well, for a program to take advantage of the multithread feature
should have to specifically written that way making use of either POSIX
API or Solaris Threads API. Otherwise
it can gain no advantage from the OS which provides such a feature.
However, IMHO, it is very advantageous to have an OS which is
multhreaded at the kernel since many of the resources that the kernel
and the add on layers manipulate are blocking in nature...For an
example take a look at the web site http://www.sun.com under the
developer products section.
They provide a paper which explains how NFS is improved if the server
is mulththreaded. The same can be extrapolated to the OS as well...
I dont know how well this OS (Solaris x86) takes advantage of this
feature itself... but the potential exists...
Did I miss something.... I will be glad if someone enlightens me.
: The MoJo Wire http://www.motherjones.com