Make CodeGen thread safe using synchronized