3.2.2: "lock requires two atomic ops"
enjoying the updated edition!
"The lock operation is more expensive than CAS because it
requires two atomic operations on the lock data structure, one for acquisition and the other for release."
this might be worth expanding upon. it's not immediately obvious to me why the unlock would need to be atomic. the rough 2x certainly jives with this explanation, and i intend to go look at some source, but i'd think it would be more:
atomic update
fence
non-atomic update
you've presumably got threads attempting to lock with a CAS looking for a sentinel representing unlocked, right? so if i update back to that sentinel in multiple steps, they're going to miss in media res, no?
feel no obligation to respond, of course.
--nick
Signature · 3 lines
nick black -=- https://www.nick-black.com to make an apple pie from scratch, you need first invent a universe.
Quoted 15 lines · nick black
enjoying the updated edition!
"The lock operation is more expensive than CAS because it
requires two atomic operations on the lock data structure, one for acquisition and the other for release."this might be worth expanding upon. it's not immediately obvious to me why the unlock would need to be atomic. the rough 2x certainly jives with this explanation, and i intend to go look at some source, but i'd think it would be more:
atomic update
fence
non-atomic update
Quoted 6 lines
you've presumably got threads attempting to lock with a CAS looking for a sentinel representing unlocked, right? so if i update back to that sentinel in multiple steps, they're going to miss in media res, no?
feel no obligation to respond, of course.
In some cases, you can release a lock with a simple store instruction. But much depends on the specifics of the implementation of the lock.
Thanx, Paul