Let's say two threads are simultaneously trying to enqueue N tensors each, into an instance of a FIFOQueue. I.e., they're calling
queue_instance.enqueue_many(T)
where T
is a list of tensors of length N
.
Let's label each tensor from the first thread as T1_1
to T1_N
, and T2_1
to T2_N
for the second thread. When all is said and done (both calls to enqueue_many
have completed), will the order be preserved? I.e., will the queue contain either [T1_1, ..., T1_N, T2_1, ..., T2_N]
or [T2_1, ..., T2_N, T1_1, ..., T1_N]
? Or could the tensors be enqueued in an interleaved manner, i.e., [T2_1, T2_2, T1_1, T2_3, T1_2, ...]
? Or, I suppose, a third option is that there is no rhyme or reason whatsoever: the tensors are enqueued in an arbitrary order.
The order within the batches enqueued by each thread is preserved. Another way of putting this is that FIFOQueue.enqueue_many()
executes atomically* with respect to other enqueue operations on the same queue.
* However, if the remaining capacity of the queue is less than the size of the batch being enqueued, it is possible to dequeue elements from the batch before the enqueue completes—i.e. you are able to enqueue batches that are larger than the capacity of the queue, and the enqueue op will block until enough elements have been dequeued.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With