3 ms·
Another example of arbitrary pointer comparison I'm familiar with is for resolving lock ordering problems. If I have a big set of locks that I need to take to c
by coldnose 8y ago
Another example of arbitrary pointer comparison I'm familiar with is for resolving lock ordering problems. If I have a big set of locks that I need to take to complete a particular operation, a simple way to prevent deadlocking is to acquire those locks in the order of their pointers.
E.g. if I have three locks I need to take,
lock_t *a = (lock_t *)0x100;
lock_t *b = (lock_t *)0x300;
lock_t *c = (lock_t *)0x200;
then I'll take them in order a, c, b;
- bluecalm 8y agoIf order of locks is important maybe it's worth considering putting them in an array.
- oconnor663 8y agoOr maybe keeping a global atomic counter, and reading a unique (to the process) value out of it every time you create a mutex?