Should waiting_queue be declared *outside* the <code> while (!IsPendingTermination()) </code> loop ?
Otherwise, I have doubts about its ability to ever be above COLLECT_WINDOW, below !