Use critical section instead of mutex.