What are you using for a stack? If you are using a queue, your consumer loop can check if the queue is empty. You could go into a loop where you wait until data is in the queue before processing it. Just check the queue for data in a loop. If no data, do nothing, if data, exit the loop and process. Put a delay in the loop, probably 10mS would do. Then your consumer would not be trying to process nothing.