Re: 3.2.2: "lock requires two atomic ops"

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux