简体   繁体   English

提升并发队列非阻塞与非等待

[英]Boost concurrent queue non-blocking vs non-waiting

I'm reading the documentation for boost::concurrent::sync_bounded_queue :我正在阅读boost::concurrent::sync_bounded_queue的文档:

https://www.boost.org/doc/libs/1_72_0/doc/html/thread/sds.html https://www.boost.org/doc/libs/1_72_0/doc/html/thread/sds.html

They have a section listed:他们列出了一个部分:

Non-waiting Concurrent Queue Operations非等待并发队列操作

but also a section listed:但也列出了一个部分:

Non-blocking Concurrent Queue Operations非阻塞并发队列操作

I don't understand the difference between non-waiting and non-blocking?我不明白非等待和非阻塞之间的区别? Surely waiting is blocking, they are the same thing?当然等待是阻塞,它们是一回事吗?

Warning: everything below is based purely on what I read in the manual.警告:以下所有内容完全基于我在手册中阅读的内容。

That manual page says for non-blocking operations:该手册页说明了非阻塞操作:

The interface is the same as the try operations but is allowed to also return queue_op_status::busy in case the operation is unable to complete without blocking.该接口与 try 操作相同,但也允许返回 queue_op_status::busy,以防操作无法在不阻塞的情况下完成。

Under the "Non-waiting Concurrent Queue Operations" section, it lists the following functions:“非等待并发队列操作”部分,列出了以下函数:

  • s = q.try_push_back(e); s = q.try_push_back(e);
  • s = q.try_push_back(rve); s = q.try_push_back(rve);
  • s = q.try_pull_front(lre); s = q.try_pull_front(lre);

Hence, it seems to me that the non-waiting operations will only fail if there's no more place in the queue.因此,在我看来,只有在队列中没有更多位置时,非等待操作才会失败。 If another thread is currently pushing data into the queue, they will wait until that other push is finished and then push themselves.如果另一个线程当前正在将数据推送到队列中,它们将等到另一个推送完成,然后再推送自己。 They'll only fail if the queue is full.只有当队列已满时,它们才会失败。

Whereas the non-blocking operations will immediately return if another thread is busy pushing data into the queue.而如果另一个线程正忙于将数据推入队列,则非阻塞操作将立即返回。 Even if there would still be enough place for new data in the queue.即使队列中仍有足够的空间容纳新数据。

Ie if the non-blocking push returns unsuccessfully that doesn't necessarily mean that the queue was full.即,如果非阻塞推送返回失败,这并不一定意味着队列已满。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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