Fixed bug with mutex in `ring_buf`.

Threads killed holding the mutex did not release it.