loop be add to protect the queue overflow or underflow