Kill dead code
Write thread mutex abstraction

Mutex and associated functions provide never-failing
lock/unlock operations and the lack of a static initializer
(a la PTHREAD_MUTEX_INITIALIZER, known to cause bugs in some
cases).