4 ms·
What you're describing about writing a mutex with cmpxchg is a spinlock. If you just use that operation it's also a very inefficient spinlock. The point of a l
by BazookaMusic 3y ago
What you're describing about writing a mutex with cmpxchg is a spinlock. If you just use that operation it's also a very inefficient spinlock.
The point of a lock free algorithm is to avoid having a thread wait on a resource and not do any work. It may do useless work that needs to be reverted, but it's not sleeping or spinning until something happens. It's not guaranteed that you can do that for every algorithm in a way that makes sense performance wise.
Here's a nice resource I used on my thesis for an adequate but not perfect spinlock with atomic instructions:
https://rigtorp.se/spinlock/ https://rigtorp.se/spinlock/
- kerkeslager 3y ago> The point of a lock free algorithm is to avoid having a thread wait on a resource and not do any work. It may do useless work that needs to be reverted, but it's not sleeping or spinning until something happens. It's not guaranteed that you can do that for every algorithm in a way that makes sense performance wise. Sure, but that seems like a much narrower statement than "you can't turn every algorithm into a lockless one". Maybe I'm just being pedantic and the person intended something more like what you said, though.