| ▲ | cowlevel 20 minutes ago | |
If it only retries because a different thread made progress, it's lock-free and total work is bounded - even though one particular thread could get very unlucky, system-wide luck is conserved. How much code's inside the CAS loop? If it's being held for less than (sticks finger in the wind) a few thousand of instructions then backoff or limits are actively counterproductive. That's how you're supposed to use a CAS loop. If it's more, you shouldn't try to invent a more clever CAS loop, you should replace it with a mutex. | ||