Guarantee 8 bytes of alignment of RawWakerVTable#158186
Conversation
|
I like this. Having unused bits in a pointer is really useful.
Would it be reasonable to add a basic example of this? It would be great for docs to not just provide the guarantee but give a real example where it's useful. |
|
@BurntSushi I'm afraid the example would be far too long and too subtle for the docs on this. |
|
Maybe we can shorten it so that it just hows how to (correctly) use those lower bits in the pointer to store something? It can be a pretty subtle thing to get correct in my experience. I know I've toiled over it. It would be a real gem to have something like that in the docs precisely where a guarantee affording such chicanery is written. |
This is similar to an earlier PR I made for
Thread::into_raw: #143859.When using
AtomicPtrfor synchronization it's incredibly useful when you've got a couple bits you can stuff metadata in. By guaranteeing thatRawWakerVTableis aligned to 8 bytes everyone can use the bottom 3 bits to signal other things, such as a critical section, etc. In particular, this can be used to portably implement anAtomicWakerwhich is always two pointers in size, no more.On almost all platforms the align is already 8 bytes, and on other platforms it might cause an infinitesimal increase in size. This guarantee is thus very useful and costs us essentially nothing.
r? libs-api
Like last time since this adds a guarantee this probably needs a FCP.