Search code examples
c++boost

Boost concurrent queue non-blocking vs non-waiting


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?


Solution

  • 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.