Re: ck_ring bug?

60 views
Skip to first unread message
Message has been deleted

Samy Al Bahra

unread,
Aug 28, 2015, 5:51:38 PM8/28/15
to Concurrency Kit

Hi Alex

Make sure it is power of 2 size.


On Fri, Aug 28, 2015, 2:44 PM Alex Forster <al...@alexforster.com> wrote:
Hi everybody,

I'm having a bit of trouble figuring out ck_ring. I have a 92-element ring (which is a power of 2), and I can't enqueue more than 3 items before the following condition fails– 

http://imgur.com/BJn01Kf.png

My guess was that this statement was meant to block enqueues when the buffer gets full. I don't understand how this ((delta & mask) == (consumer & mask)) statement is supposed to achieve that. Here's the result of a little Python test I came up with, where $mask is shown, $consumer is 0, and $delta is 0 to $mask –

$mask: 91
((4 & 91) == (0 & 91)) == True
 (0 == 0) == True
((32 & 91) == (0 & 91)) == True
  (0 == 0) == True
((36 & 91) == (0 & 91)) == True
  (0 == 0) == True

$mask: 92
((1 & 92) == (0 & 92)) == True
 (0 == 0) == True
((2 & 92) == (0 & 92)) == True
 (0 == 0) == True
((3 & 92) == (0 & 92)) == True
 (0 == 0) == True
((32 & 92) == (0 & 92)) == True
  (0 == 0) == True
((33 & 92) == (0 & 92)) == True
  (0 == 0) == True
((34 & 92) == (0 & 92)) == True
  (0 == 0) == True
((35 & 92) == (0 & 92)) == True
  (0 == 0) == True
 
I sometimes typo and transpose bitwise-and & with modulus %, which is how I accidentally realized that if I run the same test using this conditional instead, ((delta % mask) == (consumer % mask)), here's what I get:

$mask: 91
((91 % 91) == (0 % 91)) == True
  (0 == 0) == True

$mask: 92
((92 % 92) == (0 % 92)) == True
  (0 == 0) == True

If I'm right, then changing this statement to modulus looks like the originally intended outcome. Have I found a bug? Or am I completely misusing ck_ring in some way?

– Alex Forster

--
You received this message because you are subscribed to the Google Groups "Concurrency Kit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to concurrencyki...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages