used critical section instead of atomic for compatibility with /clr in the future