I have a bit of queue code that I was working on. I was trying to use a global int to keep track of the queue's size.
#define MAX 100
int size=0;
int gEnqueue=gDequeue=0;
int enqueue()
{
gEnqueue++;
if( size == MAX )
return QUEUE_FULL;
/* snip the actual queue handling */
size++;
return 0;
}
int dequeue()
{
gDequeue++;
if(!size)
return QUEUE_EMPTY;
/* snip actual queue handling */
if(size)
size--;
return 0;
}
there is of course much more code then that, but too much to post.
What is happening is the size gets stuck at the max I have set. Both functions get called an even number of times. If I dump the queue I can see that there are only 3 items in it.
What would cause this problem?
edit #1: made the code example match what I actually coded
This is not threaded.
edit #2: I am an idiot and should have done this instead of assuming. I was wrong about the calls being even to the enqueue() and dequeue().
Note to self, use real metrics not guesses.