I initialize it to 1 rather than do the combination of:

    pending = 0;
    // scanning starts, then
    pending++;

Incrementing `pending` here is for the scanning event queue. I think it applies to the your race condition question,