this can be optimized further if you remove the java-like abstractions i implemented, and you can get a solid T type instead of the void* data i used if you inline all the abstraction helpers instead of using them but it makes the code less clear
as it stands i used void* data for a reason so i could maintain the same abstraction as 'atomicmarkablereference' and behavior as java and result in a working port
this can be accounted for if you want to recode the class to have all the CAS and other functions inline
either way this is a decentish reference on how to implement something like the book in C++ -- with memory management hinted at (full epochmanager not included in this project so this demo does leak without teh full implementation)
Edit:
Technical challenges to this port and tips on porting java lock free code to c++:
-porting java lock free semantics to C++ and how to do it:
- Copy the algorithm faithfully -- even if you have to morph the language semantics or do non traditional things ot make it work (i.e. layer base class that is strictly defined and use void* data and casting to mimick javas atomicreference and node behavior rather than using a template which is reusable and modern this method will not work as seen in all other examples on github that tried too slow and double reference cost, also doesnt follow the algorithm faithfully)
- Make the semantics equivalent (epoch/hazard/markable ptr design) find a way to keep the algorithm teh same while porting and fit in a memory model that works
- Validate a working baseline -- before making the program a concrete STL nice modern template without the hax make sure the list works -- it likely will need some changes because C++ is faster and less safe so you might need more retry checks in other places or some hardening of the algorithm and debugging still. relax. dont give up.
- Then inline / optimize / modernize -- this step i have not done you can do it by removing the SNMarkablepointer class and inlining all the cas and pointer operations and slowly finding ways to undo the abstractions now that the algorithm is solid
this was a real challenge to port to C++ successfully and actually get the locks to function but if you do this and consider non traditional options you can successfully port java lock free semantics to C++