Lock mutex on writing to console