2

I'm reading the documentation for boost::concurrent::sync_bounded_queue:

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?

1 Answer 1

2

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.

Under the "Non-waiting Concurrent Queue Operations" section, it lists the following functions:

  • s = q.try_push_back(e);
  • s = q.try_push_back(rve);
  • 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.

I.e. if the non-blocking push returns unsuccessfully that doesn't necessarily mean that the queue was full.

Sign up to request clarification or add additional context in comments.

10 Comments

I wanted to hot-spin whilst retrieving elements and wasn't sure whether to use try_pull_front() or nonblocking_pull_front(). I opted for the latter
I guess if you're going to be spinning both should work. Although I would expect that the non-waiting one might be faster? Since if the non-blocking one fails due to another thread accessing the queue simultaneously you're going to be retrying the pull anyway?
This is clear when comparing s = q.nonblocking_push_back(e); and s = q.try_push_back(e); possible return values. So vote up from me. Difference is just - If the operation would block, return queue_op_status::busy,
So basically there's three types: wait_until_new_data(), wait_until_other_thread_finished(), no_wait()?
That's the way I understood it as well, yes.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.