Acquire lock before modifying ThreadCount