Miscellanious protection around pthread calls to avoid signal reentrancy.
Use pread/pwrite instead of read/write in a few cases. Cases that still
use read/write now protect the calls with a crit_enter()/crit_exit().
Protect usleep() calls with a critical section.
Protect pthread_*() calls with a critical section where applicable. Note
that calls made from cothreads do not need to be protected because the
cothreads do not take signals and are not operated as virtual cpus so they
can't preempt themselves either.
Reported-by: Trevor Kendall