Move printf into critical section