Note that there are some explanatory texts on larger screens.

plurals
  1. POCan only read one element at once of a circular buffer
    primarykey
    data
    text
    <p>I have implemented the standard single consumer, single producer queue as a circular buffer in C consisting of an array and two indexes: one for read, one for write.</p> <p>My circular buffer is of the type that returns an error if you attempt to insert an item into a full queue and uses one empty slot to distinguish between an empty ring buffer and a full one.</p> <p>While debugging it I noticed it sometime slipped into a consistent state where you could only read a single item at a time before getting the return value that meant the buffer is full, even though there was an ongoing thread that does inserts all the time.</p> <p>I assumed I must have done something silly in implementation but could not find anything. I then decided to double check the logic and re-read the <a href="http://en.wikipedia.org/wiki/Circular_buffer#Always_Keep_One_Slot_Open" rel="nofollow noreferrer">Wikipedia value</a> that describes such queues.</p> <p>Much to my surprise, I noticed the following cryptic comment in the text:</p> <blockquote> <p>If you cannot read over the buffer border, you get a lot of situations where you can only read one element at once.</p> </blockquote> <p>So, if I understand the meaning correctly, this seems to indicate that this is some sort inherit problem with this way of implementing such a ring buffer.</p> <p>Alas, my feeble brain is at a lose to understand the root cause of this problem: why is this happening? what sequence of inserts and erases can get such a ring buffer into this state?</p> <p>You help is greatly appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload