by tedunangst · 11y ago · 0 comments
lock_two_widgets(widget *a, widget *b) {
if (a < b) {
lock(&a->lock);
lock(&b->lock);
} else {
lock(&b->lock);
lock(&a->lock);
}
}Edit: Your code has undefined behavior, unless the two pointers point to the same object, which is unlikely in a realistic example.
It is defined behavior to read the bytes of any object using unsigned char.