Subject: Re: Atomic ops API
To: Jason Thorpe <thorpej@shagadelic.org>
From: Johnny Billquist <bqt@softjar.se>
List: tech-kern
Date: 03/16/2007 10:25:53
Jason Thorpe wrote:
>
> On Mar 15, 2007, at 11:26 AM, matthew green wrote:
>
>> Anyway, I've decided to stick with "cas" as "compare-and-store".
>>
>> i really wish you wouldn't. as an example, google gives:
>>
>> Results 1 - 10 of about 19,400 for "compare and swap" cas
>> Results 1 - 10 of about 50 for "compare and store" cas
>
> And how many "compare-and-swap" functions return the old value? Many
> of them just return true or false.
I was just wondering, is the returned value even meaningful? I mean,
either it returns the same value as what is compared against, in which
case a swap has been performed, or it returns something else. That
something else, is that ever possible to use in some meaningful way? I
mean, it's a copy of a value that very well could have changed before
you even have a chance to act upon it.
However, for code already using a cas then, I would guess that they
check for a return value of ==cmp or !=cmp. So why not have your cas
function return that, Jason? That should then not break anything, and
that can be implemented internally as a compare_and_store with a simple
wrapper to return cmp or ~cmp.
Or is some code actually using the return value in some more clever way
in case it's not ==cmp.
Johnny