I could be wrong about this, but I thought it better to ask a stupid question & learn from it.
If one thread gets suspended (or there's a cache-miss or something) in pop() between testing if old_head isn't nullptr, and the compare/exchange with head/old_head/old_head->next, and another thread succeeds in its compare/exchange with chain_pending_nodes() as called by chain_pending_node() as called by try_reclaim() when threads_in_app != 1 ... then couldn't the stack get replaced by the list of to-be-deleted nodes?
If the compare/exchange in pop() doesn't begin until the thread resumes, then I don't think it won't detect that old_head->next has changed.
The solution, I believe, would be to have a separate node* next_free in struct node.
I could be wrong about this, but I thought it better to ask a stupid question & learn from it.
If one thread gets suspended (or there's a cache-miss or something) in
pop()between testing ifold_headisn'tnullptr, and the compare/exchange with head/old_head/old_head->next, and another thread succeeds in its compare/exchange withchain_pending_nodes()as called bychain_pending_node()as called bytry_reclaim()whenthreads_in_app != 1... then couldn't the stack get replaced by the list of to-be-deleted nodes?If the compare/exchange in
pop()doesn't begin until the thread resumes, then I don't think it won't detect thatold_head->nexthas changed.The solution, I believe, would be to have a separate
node* next_freeinstruct node.