Replies: 1 comment 5 replies
-
This is a very interesting and worthy discussion, so I moved it from the Issue list to the Discussion. Here are our thoughts on this topic. Firstly, our view is that For example, Therefore, the size of bq::ring_buffer can be adjusted according to different use scenarios, as described in our README.MD. Regarding your first example, it is also a type of block caused by insufficient resources. For the consumer thread, the producer thread's data is a resource. If the resource isn't ready, indeed, the consumer has nothing to do. However, the ring buffer itself doesn't block in this situation; it returns a failure, and then the log's worker, as an external scheduler, can choose to temporarily sleep. Regarding "No further data from other producers can be consumed," I'd like to clarify that bq::ring_buffer uses a multiple-producer, single-consumer setup, rather than multiple producers and multiple consumers, because it is designed specifically for logging. This is why the code of These are some of our views, and we welcome further discussion. |
Beta Was this translation helpful? Give feedback.
-
The used algorithm can be reduced to
Consumer and producers rely on a flag(
status
) indicating whether data is ready. If a producer is suspended at#1
, then the consumer is blocked at#2
, waiting the producer to finish writing. No further data from other producers can be consumed. When the ring buffer become full, all other producers are blocked by the consumer which is blocked by the suspended producer. No thread can make progress until the suspended producer finish writing.Beta Was this translation helpful? Give feedback.
All reactions