Closed hahasofia closed 2 years ago
Do you think these two functions
Front
andPushFront
can be added in?
In a multi-threaded application front
would return a reference to an element in the queue. By the time the element is examined, another thread may have pop
ed this element, leaving you with an invalid reference. For this reason front
is not an applicable use case for this non-blocking queue.
May be try_pop
is what you need.
Alternatively, you may like to use a non-blocking queue which is based on hazard- or smart-pointers, or use a blocking queue, e.g. std::vector
with std::mutex
.
Dear author, I have a requirement such as to inquire the first element of queue but not pop it. It's just like what Front() does in std::vector. Also I want to push one element in the front of queue. Do you think these two functions Front and PushFront can be added in? Thank you.