fix pthread deadlocks