Serialize access to (runtime thread) internals.
Multiple processors may use the thread system simultaneously, so its
procedures and timer interrupt handler must arrange to serialize.
They must lock/unlock an OS-level mutex and run without interrupts.
While the mutex is locked, they must not signal errors and may not
invoke arbitrary hooks, handlers, etc. (The mutex is not recursive.)
Inside the mutex's atomic sections a LOCKED? flag is set. Asserts
check that the thread system is locked when necessary.
The channel-close and process-delete primitives are called inside the
thread system's atomic deregistration operations to ensure that the
timer interrupt or wait-for-io (i.e. test-select-registry called on
another processor) do not use the invalid descriptors.