This introduces a thread-state object and moves various C globals
there.  It also introduces #defines for these globals to avoid a
monster patch.

The #defines mean that this patch also has to rename a few fields
whose names clash with the defines.

There is currently just a single "thread"; so this patch does not
impact Emacs behavior in any significant way.
This parameterizes the GC a bit to make it thread-ready.

The basic idea is that whenever a thread "exits lisp" -- that is,
releases the global lock in favor of another thread -- it must save
its stack boundaries in the thread object.  This way the boundaries
are always available for marking.  This is the purpose of
flush_stack_call_func.

I haven't tested this under all the possible GC configurations.
There is a new FIXME in a spot that i didn't convert.

Arguably all_threads should go in the previous patch.
This introduces the low-level system threading support.  It also adds
the global lock.  The low-level support is a bit over-eager, in that
even at the end of the present series, it will not all be used.  I
think thiat is ok since I plan to use it all eventually -- in
particular for the emacs lisp mutex implementation.

I've only implemented the pthreads-based version.  I think it should
be relatively clear how to port this to other systems, though.

I'd also like to do a "no threads" port that will turn most things
into no-ops, and have thread-creation fail.  I was thinking perhaps
I'd make a future (provide 'threads) conditional on threads actually
working.

One other minor enhancement available here is to make it possible to
set the name of the new thread at the OS layer.  That way gdb, e.g.,
could display thread names.
This introduces some new functions to handle the specpdl.  The basic
idea is that when a thread loses the interpreter lock, it will unbind
the bindings it has put in place.  Then when a thread acquires the
lock, it will restore its bindings.

This code reuses an existing empty slot in struct specbinding to store
the current value when the thread is "swapped out".

This approach performs worse than my previously planned approach.
However, it was one I could implement with minimal time and
brainpower.  I hope that perhaps someone else could improve the code
once it is in.
This turns thread_state into a pseudovector and updates various bits
of Emacs to cope.
This adds most of the thread features visible to emacs lisp.

I roughly followed the Bordeaux threads API:

http://trac.common-lisp.net/bordeaux-threads/wiki/ApiDocumentation

... but not identically.  In particular I chose not to implement
interrupt-thread or destroy-thread, but instead a thread-signalling
approach.

I'm still undecided about *default-special-bindings* (which I did not
implement).  I think it would be more emacs-like to capture the let
bindings at make-thread time, but IIRC Stefan didn't like this idea
the first time around.

There are one or two semantics issues pointed out in the patch where I
could use some advice.
This supplies the mutex implementation for Emacs Lisp.

A lisp mutex is implemented using a condition variable, so that we can
interrupt a mutex-lock operation by calling thread-signal on the
blocking thread.  I did things this way because pthread_mutex_lock
can't readily be interrupted.
This adds some tests of the threading code.
This adds names to mutexes.  This seemed like a nice debugging
extension.
This adds thread-blocker, a function to examine what a thread is
blocked on.  I thought this would be another nice debugging addition.
fix a latent bug in process.c

	* process.c (wait_reading_process_output): Check Writeok bits,
	not write_mask.
Prepare process.c for threads by not having global select masks.
The next step is to make it so selects can choose fds by thread.
process changes

This changes wait_reading_process_output to handle threads better.  It
introduces a wrapper for select that releases the global lock, and it
ensures that only a single thread can select a given file descriptor
at a time.

This also adds the thread-locking feature to processes.  By default a
process can only have its output accepted by the thread that created
it.  This can be changed using set-process-thread.  (If the thread
exits, the process is again available for waiting by any thread.)

Note that thread-signal will not currently interrupt a thread blocked
on select.  I'll fix this later.
add test case for I/O switching