httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From (Robert S. Thau)
Subject Re: New threaded server snapshot
Date Sun, 16 Jun 1996 23:16:49 GMT
  I haven't looked at the code, but I am curious... What exactly is
  required for a threaded package? i.e. is "generic" UNIX not acceptable,
  or maybe stdio not up to snuff?

Well, the code comes with its own threads package (something I whipped
together), and a stdio replacement library which comes from Bell Labs,
and provides hooks which are useful for (among many other things) dealing
with the threads code.

The threads package itself works by using the usual trick of using longjmp()
to context-switch.  The hard part of this is figuring out how to set up a
jmp_buf for the context of a new thread before the code of that thread has
first run.  (In particular, you want a longjmp() into that thread's context
to start running on the thread's own stack, and not the stack of the
thread that created it).

Getting thread kickoff to work is probably the trickiest part of porting
the package to a new platform (the rest is pretty much machine-independant,
with the usual hiccups involving gratuitous differences in the behavior of
non-blocking I/O on various platforms, and the like --- no worse than
porting a web server, in other words).

There is a generic thread kickoff routine which does a little
sleight-of-hand with the sigstack() or sigaltstack() system call ---
if the machine you're porting to supports one of these two (non-Posix)
system calls, you may be able to just use one or the other.  (So far
as I know, BTW, this sigstack() trick is original --- if anyone has
seen another use, please let me know).  However, sigstack() or some
variant is not always available, and sometimes acts finicky; in those
cases, you've got to write a few lines of machine dependant C code to
set up the jmp_buf explicitly.

(Note that "stackbottom" is the high address and "stacktop" is the low
address if you wind up poking into the jmp_buf directly --- this is
the lovely bit of nomenclature that had Ben at my throat.  I should
probably change it to stackhiaddr and stackloaddr or something like
that to eliminate the ambiguity...  maybe in the next release).

BTW, the threads code comes with its own small set of tests --- I'd
strongly recommend getting those to work before messing around with
sfio or the full server.  (For one thing, they're a *lot* smaller).

I've managed to avoid assembly almost completely, BTW --- to date,
there is only one assembly-language instruction in the package, a
branch needed on AIX to suppress an unwanted error check in longjmp().
To those who look at the thing and groan --- I never said it was
elegant, but in my book, small, ugly, and machine-dependant beats big,
ugly, and machine-dependant any day of the week.  In any case, all
other platforms run without any assembly at all.


View raw message