fixed potential deadlock with locks