6 ms·
If lock calls include a memory barrier, which they should, then they cannot be reordered. Edit: Your code has undefined behavior, unless the two pointers point
by just_curioussss 11y ago
If lock calls include a memory barrier, which they should, then they cannot be reordered.
Edit: Your code has undefined behavior, unless the two pointers point to the same object, which is unlikely in a realistic example.
- ufo 11y agoYes, the pointer comparison is UB but if the compiler didn't go out of its way to screw you over UB code then it would be a reasonable way to prevent deadlock.
- just_curioussss 11y agoThere is a defined method for comparing such pointers. Take unsigned char pointers to them and inspect their bytes. Then write your code, using that information, that does the comparison, assuming you know your architecture. It is defined behavior to read the bytes of any object using unsigned char.
- kbwt 11y agoAlternatively, if the implementation supports uintptr_t, you can convert to that and then compare the respective integral values.