20 template <
typename _ValueT,
typename _WaitPolicyT = null_wait_policy>
class stack{
23 using value_type = _ValueT;
24 using wait_policy_type = _WaitPolicyT;
26 stack(wait_policy_type oWait = wait_policy_type()) : _Root(
nullptr), _WaitPolicy(oWait){}
30 auto pNode = _Root.load();
31 if (_Root.compare_exchange_strong(pNode, pNode->_Next)){
38 src._Root.store(
nullptr);
41 if (&src ==
this)
return *
this;
42 std::swap(_Root, src._Root);
49 bool try_pop(value_type& oRet){
50 auto oTmp = _Root.load();
51 if (!oTmp)
return false;
52 if (!_Root.compare_exchange_strong(oTmp, oTmp->_Next)){
60 void push(
const value_type& value){
61 typename node::pointer pNode =
new node;
62 pNode->_Value = value;
64 pNode->_Next = _Root.load();
65 if (_Root.compare_exchange_strong(pNode->_Next, pNode)){
74 while (!try_pop(oRet)){
82 using pointer = node *;
83 using atomic_ptr = std::atomic<pointer>;
87 typename node::atomic_ptr _Root;
88 _WaitPolicyT _WaitPolicy;
shared declarations for the concurrent namespace
A lock-free LIFO stack multiple threads can push and pop items concurrently.