Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template <class T>
- bool CASStack<T>::pop(T& ret) {
- node<T>* old_head = head.load(std::memory_order_relaxed);
- if(old_head == nullptr) {
- return false;
- }
- // from here on we can assume that there is an element to pop
- node<T>* new_head;
- do {
- new_head = old_head->next;
- } while(!head.compare_exchange_weak(old_head, new_head, std::memory_order_acquire, std::memory_order_relaxed));
- ret = old_head->data;
- return true;
- }
Add Comment
Please, Sign In to add comment