简体   繁体   中英

Does queue enqueue_many block unitll all items are on the queue?

I'm working on a problem where I need to guarantee the order of items on the queue, however, I would also like to use multiple threads to do this. Thus I'm wondering if a call to enqueue_many will ensure that those items are placed in order?

One solution to this is to only use one thread to enqueue items, however that is not optimal.

The documentation only mentions blocking in the case where the queue is full.

tf.QueueBase.enqueue_many(vals, name=None)

Enqueues zero or more elements to this queue.

This operation slices each component tensor along the 0th dimension to make multiple queue elements. All of the tensors in vals must have the same size in the 0th dimension.

If the queue is full when this operation executes, it will block until all of the elements have been enqueued.

At runtime, this operation may raise an error if the queue is closed before or during its execution. If the queue is closed before this operation runs, tf.errors.AbortedError will be raised. If this operation is blocked, and either (i) the queue is closed by a close operation with cancel_pending_enqueues=True, or (ii) the session is closed, tf.errors.CancelledError will be raised. Args:

 vals: A tensor, a list or tuple of tensors, or a dictionary from which the queue elements are taken. name: A name for the operation (optional). 

Returns:

The operation that enqueues a batch of tuples of tensors to the queue.

https://www.tensorflow.org/versions/r0.10/api_docs/python/io_ops/queues#QueueBase

Empirically they seem to be atomic. IE, here's an example that enqueues a large block of zeros and ones simultaneously, and then checks if there has been any mixing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM