add critical section guard