Keep track of number of of sheets processed rather than just posting signals to the semaphore and relying on the wait loop to do the counting. Every now and then a signal was missed and then wait loop wouldn't exit.