Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Tensorflow's QueueBase.enqueue_many preserve order across threads?

Tags:

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.

like image 671
eriophora Avatar asked Mar 30 '16 21:03

eriophora


1 Answers

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.

like image 153
mrry Avatar answered Oct 11 '22 05:10

mrry