After thinking a little about it this issue may be solved by just pushing some kind of terminator value in the queue when terminate is called, I will try to have a look later.