In a well-known book "The Art of Multiprocessor Programming" by Herlihy, 
Shavit some of lock-free and wait-free algorithms utilize Java's template 
AtomicMarkableReference<T> type. It allows to perform single atomic CAS 
operation on the pair consisting of T reference and boolean mark.

There is no similar type in C/C++/Go stdlib, but at least in C++ it's 
possible to model it using bit stealing approach (see C++ example 
<https://stackoverflow.com/questions/40247249/what-is-the-c-11-atomic-library-equivalent-of-javas-atomicmarkablereferencet>).
 
On x86_64 arch only 48 bits of 64 bits are actually used, so one can store 
arbitrary data in the remaining 16 bits, and work with the whole pointer 
and the data atomically.

As far as I understand, there are two requirements to implement this 
approach:

   1. Pointers must be aligned.
   2. Pointer's low bits must be clear (if you want to store something like 
   bool in this area, it must not be already occupied).

But some stackowerflow users have questioned 
<https://stackoverflow.com/questions/67409134/go-pointer-bit-stealing-technique#comment119153794_67409134>
 
whether these remaining bits are really free in Go. Perhaps Go runtime 
already uses these area for GC or some other background routines?

So is it possible to use pointer bit stealing technique in Go? Are there 
any working examples?

Thank you

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/b9e78da6-2a88-444b-9d83-64c2341bdc22n%40googlegroups.com.

Reply via email to