Re:Yes, You Have Been Writing SPSC Queues Wrong
by rkevingibson on Thursday December 15, 2016 @01:52PM
(#13187077)
I'm curious what you think the problems are that unbounded indices causes? Unsigned overflow is well defined in C++, so I don't see the problem here. AFAIK, the only issue would be with requiring power of 2 sizes.
[ Parent
| on HN ]
Re:Yes, You Have Been Writing SPSC Queues Wrong
by loeg on Thursday December 15, 2016 @02:29PM
(#13187424)
Yeah. Just requires power of 2 sizes and handling of write_idx < read_idx.
Re:Yes, You Have Been Writing SPSC Queues Wrong
by ashtuchkin on Thursday December 15, 2016 @05:09PM
(#13188971)
AFAIK write_idx < read_idx case is handled automatically by doing the unsigned subtraction.
Power of 2 requirement stands, though.
Re:Yes, You Have Been Writing SPSC Queues Wrong
by gpderetta on Thursday December 15, 2016 @05:20PM
(#13189105)
Yes, this exact trick is used for tcp sequence numbers, for example, which are allowed to overflow, and as long as the unack'd bytes are less than 231 everything works fine as long as computation is done with unsigned integers.