Change pthread mutex lock to solve crash issue