code: def testRecursiveCriticalSectionAccessViaCapturedTensorIsProtected(
      self,
  ):
      # This one is subtle; and we're being overly cautious here.  The
      # deadlock we are ensuring we catch is:
      #
      # to_capture = CS[lambda x: x + 1](1.0)
      # deadlocked = CS[lambda x: x + to_capture](1.0)
      #
      # This would have caused a deadlock because executing `deadlocked` will
      # lock the mutex on CS; but then due to dependencies, will attempt
      # to compute `to_capture`.  This computation requires locking CS,
      # but that is not possible now because CS is already locked by
      # `deadlocked`.
      #
      # We check that CriticalSection.execute properly inserts new
      # control dependencies to its lock to ensure all captured
      # operations are finished before anything runs within the critical section.
      cs = critical_section_ops.CriticalSection(shared_name="cs")
      fn = array_ops.identity
      to_capture = cs.execute(lambda: fn(1.0))
      fn_captures = lambda x: x + to_capture
      to_capture_too = array_ops.identity(to_capture)
  
      ex_0 = cs.execute(lambda: fn_captures(1.0))
  
      with ops.control_dependencies([to_capture]):
          # This is OK because to_capture will execute before this next call
          ex_1 = cs.execute(lambda: fn_captures(1.0))
  
      dependency = array_ops.identity(to_capture)
  
      fn_captures_dependency = lambda x: x + dependency
  
      ex_2 = cs.execute(lambda: fn_captures_dependency(1.0))
  
      with ops.control_dependencies([to_capture_too]):
          ex_3 = cs.execute(lambda: fn_captures_dependency(1.0))
  
      # Ensure there's no actual deadlock on to_execute.
      self.assertEqual(2.0, self.evaluate(ex_0))
      self.assertEqual(2.0, self.evaluate(ex_1))
      self.assertEqual(2.0, self.evaluate(ex_2))
      self.assertEqual(2.0, self.evaluate(ex_3))
  
imports: import itertools
  from absl.testing import parameterized
  from tensorflow.python.data.experimental.ops import prefetching_ops
  from tensorflow.python.data.ops import dataset_ops
  from tensorflow.python.eager import context
  from tensorflow.python.eager import def_function
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import test_util
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import cond
  from tensorflow.python.ops import control_flow_assert
  from tensorflow.python.ops import control_flow_ops
  from tensorflow.python.ops import control_flow_v2_toggles
  from tensorflow.python.ops import critical_section_ops
  from tensorflow.python.ops import resource_variable_ops
  from tensorflow.python.ops import while_loop
  from tensorflow.python.platform import test
  from tensorflow.python.platform import tf_logging
label_desc: Use image node_id 7 for calling the CriticalSectionTest obj's underlying member method code with example usage: obj.testRecursiveCriticalSectionAccessViaCapturedTensorIsProtected() without return types