Locks vs Lock-Free
This cluster discusses the performance, use cases, and trade-offs of locks (mutexes, spinlocks) versus lock-free algorithms and atomics in concurrent programming, including when one outperforms the other and common pitfalls like contention.
Activity Over Time
Top Contributors
Keywords
Sample Comments
In which circumstances, lock-free algorithms are NOT better than locking ones?
locks and mutexes will perform worse than things like atomic increment.
Seems like this is what mutexes were invented for
what are alternatives to mutexes? I find them a software engineering disaster waiting to happen.
Doesn’t the need for locks make it incredibly slow?
From what I have heard they use manual spin locks. Generally, spin locks are not a good idea unless you want to dedicate the entire machine to a single application. If the process a spinlock waits on gets suspended, you're burning CPU time for nothing. The OS thinks a spinlock making zero progress is actually a high priority process, so it is starving the suspended process from making progress.
Spin locks are not very power efficient.
Aren't they "lock-free" though?
Why would lockless be slower? Is it ever slower?
What's the problem with mutexes?