aba

Lock Free stack implementation idea - currently broken

微笑、不失礼 提交于 2019-12-11 06:19:46
问题 I came up with an idea I am trying to implement for a lock free stack that does not rely on reference counting to resolve the ABA problem, and also handles memory reclamation properly. It is similar in concept to RCU, and relies on two features: marking a list entry as removed, and tracking readers traversing the list. The former is simple, it just uses the LSB of the pointer. The latter is my "clever" attempt at an approach to implementing an unbounded lock free stack. Basically, when any

Is this hazard pointer example flawed because of ABA issue?

帅比萌擦擦* 提交于 2019-12-10 13:18:10
问题 In the book C++ Concurrency in Action, the author gave an example of using hazard pointer to implement a lock-free stack data structure. Part of the code is as follows: std::shared_ptr<T> pop() { std::atomic<void*>& hp=get_hazard_pointer_for_current_thread(); node* old_head=head.load(); node* temp; do { temp=old_head; hp.store(old_head); old_head=head.load(); } while(old_head!=temp); // ... } The description says that You have to do this in a while loop to ensure that the node hasn’t been