Re: 3.2.2: "lock requires two atomic ops"

"Paul E. McKenney" <[email protected]>
Newsgroups org.kernel.vger.perfbook
Message-ID <3d1bb928-2608-42d4-822b-d08b04817b19@paulmck-laptop>
On Tue, Jun 13, 2023 at 08:15:28PM -0400, nick black wrote:
> 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.

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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.