In reply to Pooja Pathak:
But your write() method is a function consuming no time. If the queue is empty, the write() executes first, followed by the read(), the read succeeds. If the read()_ executes before the write() it fails. So you need to delay the push_front() by putting it inside a fork/join_none