// wait until queue is empty and all threads are // waiting for new work. while (!queue.empty()) {Thread::sleep(200); }

Thread::sleep(500);

In code we need a Sleep 200 to complete last operation thread because the queue is empty but some thread needs more time to complete its work,now, Sleep is very bad for my application(it run at 300-400 Hz).So i resolved adding a new attribute in NQ's code: