add criticalsection