Re: Async IO

Nathan Bryant (nathan@burgessinc.com)
Mon, 27 Jan 1997 22:08:42 -0500 (EST)


On Mon, 27 Jan 1997, Greg Alexander wrote:

> On Mon, 27 Jan 1997, Nathan Bryant wrote:
>
> > On Sun, 26 Jan 1997, Greg Alexander wrote:
> >
> > > You only need to use one signal, then the signal handler will look at some
> > > shared memory to see what the signal was for. And there's no really good
> > > reason that i know of to not use SIGHUP, SIGCHLD, SIGIO, SIGPWR, etc.
> >
> > Using shared memory from signal handlers isn't easy. The pthreads
> > synchronization routines can't be called from signal handlers, because
> > they rely on signals to wake up a task that's blocked on a mutex or
> > condition.
>
> aren't you over-complexicating? All you need for threading is clone(2) and
> mmap(2).

Not at all. Firstly, when you do clone() the new thread shares its address
space with the first one, so you don't need mmap() for shared memory.
Secondly, any program which has multiple threads accessing shared memory
has to have a way to synchronize access to that shared memory. If two
threads need to write to the same area of memory at the same time, and you
don't use any sort of locking, you're screwed.

Locking can be accomplished by having one thread wait to access the
shared memory until the other thread is done. The way the pthreads
library (aka LinuxThreads) accomplishes this is by calling sigsuspend() to
wait for a signal which gets sent when the other thread is done accessing
the shared data.

Since you can't receive a signal while you're in a signal handler, you
have to sit in a tight loop doing nothing while you wait for access. And
we all know that sitting in tight loops doing doesn't do good things for
your CPU idle time ;)

>
> > Async I/O can be done on linux, but it can't be done portably until Linux
> > gets better signal support.
>
> mmap had darn better be portable. :) And you can do it with just fork.

Ouch! fork is really slow.

What I meant was, Linux won't have POSIX-compliant asynchronous I/O until
it gets POSIX-compliant signals.

>
> Greg Alexander
> http://www.cia-g.com/~sietch/
>

+-----------------------+---------------------------------------+
| Nathan Bryant | Unsolicited commercial e-mail WILL be |
| nathan@burgessinc.com | charged an $80/hr proofreading fee. |
+-----------------------+---------------------------------------+