3 ms·
You can fix this scenario by incrementing the next_token when you commit the critical section instead of when you enter (if that's possible for your domain). Th
by singron 2y ago
You can fix this scenario by incrementing the next_token when you commit the critical section instead of when you enter (if that's possible for your domain). This essentially makes it an optimistic lock instead of a pessimistic lock. Two threads can get the same fence token, but only one will be able to commit.
You can often rephrase and algorithm without a commit step into one that has one, although sometimes it can feel more complicated. E.g. instead of doing A and B in a critical section, commit an intent to do A and B, and then let an idempotent process execute that intent.