On 2001-09-03 09:36:53 +0300, Igor Khasilev wrote:
> On Sun, 2 Sep 2001, David Schwartz wrote:
>
> > > I was playing around with pth trying to find out how to use it
> > > with a server using disk I/O. The program below is based on the
> > > example found in the manual page. If I comment out the call to
> > > pth_yield in the handler, the program will serialize all requests.
> > > What is the "right" way to make pth schedule other threads, like
> > > the main thread accepting new connections?
> >
> > Really, the only answer to your question is that Pth provides
> > cooperative multi-tasking. It's up to you to decide when you want
> > your threads to yield the CPU to other threads that might be able to
> > run. One way to do this is to put 'pth_yield' calls in strategic
> > places. If you really need I/O concurrency, you really shouldn't use
> > Pth and on FreeBSD 4, you should use the LinuxThreads port.
>
> Just for info: There is also some further developement based on the
> pth, where Pth threads run on top of native threads, which give you
> two level N:M threading. Sorry, can't supply url, it is somewhere on
> the IBM site.
Really, I don't think this will help too much. My understanding is that
the Linux kernel (the target of the IBM effort) and indeed most, if not
all Unix-ish kernels do not support poll()/select() or
O_NDELAY/O_NONBLOCK on disk files. Or more accurately, that the file
descriptors are always considered "ready".
This can be a problem in highly concurrent servers, where reading a
block of data from disk that takes 0.1 seconds means a delay in tens
or hundreds of other threads of 0.1 seconds.
The IBM Pth provides a separate kernel thread for each CPU on the
machine. This is great for network I/O, where the kernel buffers reads
and writes between the application and the network, but not so great for
disk I/O, because of the above limitations.
The "right" way to do this is to use an asynchronous I/O mechanism, e.g.
/dev/poll (on Solaris), kqueues (on FreeBSD), or POSIX aio. A good page
on this topic can be found here:
http://www.kegel.com/c10k.html
Another (portable?) approach is to use pthreads, creating a separate
thread for each disk device and using condition variables to request
read/write to disks from other threads. I don't think this is currently
possible with either the stock Pth or the IBM version thereof however.
--
Shane
Carpe Diem
______________________________________________________________________
GNU Portable Threads (Pth) http://www.gnu.org/software/pth/
User Support Mailing List [EMAIL PROTECTED]
Automated List Manager (Majordomo) [EMAIL PROTECTED]