lock the critical section