Loop up to MAX_THREADS instead of h->s.avctx->thread_count to free the thread