Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

lock-free memory reclamation with 64bit pointers

Tags:

c++

lock-free

Herlihy and Shavit's book (The Art of Multiprocessor Programming) solution to memory reclamation uses Java's AtomicStampedReference<T>;.

To write one in C++ for the x86_64 I imagine requires at least a 12 byte swap operation - 8 for a 64bit pointer and 4 for the int.

Is there x86 hardware support for this and if not, any pointers on how to do wait-free memory reclamation without it?

like image 377
JDonner Avatar asked Dec 08 '22 07:12

JDonner


2 Answers

Yes, there is hardware support, though I don't know if it is exposed by C++ libraries. Anyway, if you don't mind doing some low-level unportable assembly language trickery - look up the CMPXCHG16B instruction in Intel manuals.

like image 185
stormsoul Avatar answered Dec 21 '22 03:12

stormsoul


Windows gives you a bunch of Interlocked functions that are atomic and can probably be used to do what you want. Similar functions exist for other platforms, and I believe Boost has an interlocked library as well.

Your question isn't super clear and I don't have a copy of Herlihy and Shavit laying around. Perhaps if you elaborated or gave psuedo code outlining what you want to do, we can give you a more specific answer.

like image 43
i_am_jorf Avatar answered Dec 21 '22 01:12

i_am_jorf