A comment by IanAbbott led me to the bug. The issue is the comparison I was doing to decide whether or not the queue needed to be realloc'ed. I was comparing against pool->waiting_in_queue
, which is incorrect since this is the number of unstarted jobs. What I needed to do was this:
while (pool->queue_length >= (pool->queue_capacity - 1)) {
That is, comparing the length of the queue itself, and not the number of unstarted jobs.
Thanks for all the helpful comments and advice :)