Thank you Eric, that was awesome! It's better to do a single time then hear 100 times :) The only thing, please update the pop_front() function to update the "tail". Otherwise, push_back() will stop working if all tasks were done once.
I think the problem is that when you pop the last element in the list, the tail pointer will still be pointing at that last element. So you need to detect that case and update tail to point at the head node. Something like: task* front = std::exchange(head.next, head.next->next); if (front == tail) { tail = &head; } return front;
This talk finally made me understand the whole thing a little bit more. Thanks
Thank you Eric, that was awesome! It's better to do a single time then hear 100 times :)
The only thing, please update the pop_front() function to update the "tail". Otherwise, push_back() will stop working if all tasks were done once.
You're right, push_back() wasn't updating the tail. Oops!
What would it look like then? | Which line should be added/modified? Thank you.
I think the problem is that when you pop the last element in the list, the tail pointer will still be pointing at that last element. So you need to detect that case and update tail to point at the head node. Something like: task* front = std::exchange(head.next, head.next->next); if (front == tail) { tail = &head; } return front;