// Some compare methdods can be faster than collecting,
// so we can reach the end of list while collect is running.
// In this case we must wait for a while for new items to be
// added to the list.
if (pos == NULL && pCtxt->m_bCollectReady == FALSE)
pos = prevPos;
} while (pos == NULL);
Compare thread might enter the loop after processing last item, but before collect thread sets pCtxt->m_bCollectReady to TRUE.
While the fix is obvious, I'd actually prefer to get rid of the busy-waiting thread by synchronizing threads through a counting semaphore.
Log in to post a comment.