Lack of round robin?

Recently, in an interview, I was asked the disadvantage of using a round robin. I could not think of anything. Searching the Internet the only answer I found is that it is difficult to implement than a linear queue :). Is there any other disadvantage?

+7
source share
3 answers

I would say that the biggest drawback of a circular queue is that you can only store queue.length elements. If you use it as a buffer, you limit the depth of your story.

Another lesser disadvantage is the difficulty of transferring an empty queue from a full queue without storing additional information.

+1
source

The answer that the interviewer was looking for probably depends on some additional context that is not in the above question.

For example, often circular queues are considered for highly competing producer / consumer systems. When the queue is full, operations at the front and back of the queue may compete for the same cache lines, and this can be a problem in such contexts.

Or maybe the interviewer wanted you to talk about how much easier it is to make a queue related to blocking in a garbage collected language compared to a massive circular queue.

Or maybe it's just about how you can use the vector containers provided by your language much better if you use a linear queue with periodic switching instead of a circular queue.

+1
source

It seems to me that any code that crosses the queue will have to track the first node in order to detect the end of the traverse. But in a multi-threaded environment, another thread can remove the first node, which causes the move thread to go into an infinite loop. Thus, the passing thread would have to keep the first node blocked for the duration of its loop through the queue.

0
source

All Articles