News for hackers. Stuff that matters.
Re:What every systems programmer should know about lockless ... by dragontamer on Thursday November 02, 2017 @01:32PM (#15612402)
> Also any lock implementations also use a cas or equivalent internally

But if you have a data-structure with say, 20 ints... you have two approaches.

1. Use a mutex (which may be CAS-based under the hood) at the beginning and end: 1 lock and 1 unlock. The 20-ints are then accessed with non-atomic operations.

2. Use atomic operations on those 20-ints. But in this case, you pay the "atomics cost" each time.

In many cases, #1 may be faster than #2.

-----

Sorry for the 2nd response, but this is a different idea than what I was talking in my 1st response.

Re:What every systems programmer should know about lockless ... by gpderetta on Thursday November 02, 2017 @01:49PM (#15612564)
Using 20 cas to update 20 ints it is probably not the best idea. There are significantly more than two approaches (seqlocks, RCU, persistent data structures, etc). Which one works best depends on the actual use case.