title: Is is thread safe for `tf.data.Dataset.from_generator` to retrieve data from a modifiable buffer?
body: <p>I want to use <code>tf.data.Dataset.from_generator</code> with a modifiable buffer such as one defined below</p>
  
  <pre class="lang-py prettyprint-override"><code>class Buffer:
      def __init__(self):
          self.memory = np.zeros(10)
  
      def modify_data(self, indices, values):
          self.memory[indices] = values
  
      def sample(self):
          while True:
              indices = np.random.randint(0, 10, 2)
              yield self.memory[indices]
  
  buffer = Buffer()
  ds = tf.data.Dataset.from_generator(
      buffer.sample, output_types=tf.float32, output_shapes=(2, ))
  ds = ds.prefetch(tf.data.experimental.AUTOTUNE)
  </code></pre>
  
  <p>I'm wondering if this code is thread-safe: Would <code>modify_data</code> be called at the same time <code>sample</code> yields an entry? Should I add a lock to this class if I don't explicitly use this class in a multi-threading way?</p>