from tensorflow.python.ops import control_flow_ops

    # Make sure update_ops are computed before total_loss.
    if update_ops:
      with tf.control_dependencies(update_ops):
        barrier = tf.no_op(name='update_barrier')
        self.d_losses[-1] = control_flow_ops.with_dependencies([barrier], self.d_losses[-1])
        self.g_losses[-1] = control_flow_ops.with_dependencies([barrier], self.g_losses[-1])
        self.d_loss_real = control_flow_ops.with_dependencies([barrier], self.d_loss_real)
        self.d_loss_fake = control_flow_ops.with_dependencies([barrier], self.d_loss_fake)
