tma@progress.COM (Tim Atchison) (12/07/90)
I am looking for a test-and-set instruction (or something like it) on the
IBM RS/6000. I know that the assembly code is proprietary, but I found a
compare-and-set (cs) system call that looks like it does the same thing.
Unfortunately, I can't find this command in my doc set. Could someone show
me how to use this call ?
The only information that I have is:
int cs (int *dest, int compare, int value)
It has the following logic:
if (compare == *dest) {*dest = value; return(0);}
else return(1);
--------------------------------------------------------------------------------
Timothy M. Atchison UUCP: mit-eddie!progress!tma
Progress Software Corp. Internet: tma@progress.com
5 Oak Park
Bedford, MA 01730marc@arnor.uucp (12/10/90)
"cs" follows the "compare and swap" strategy used in the IBM S/370. It is described in the on line documentation, which includes an example. The call is: cs(int *dest, int comp, int value); and the idea is that it will store value in destination only if destination's old value was comp. This is of course done atomically. cs returns 0 if it succeeds, 1 if the old value of destination did not match comp. For examle, to set a simple spin lock in int lock where the lock is 0 when free and 1 when held: while (cs(&lock,0,1)); compare and swap can also be used to do many linked list manipulations directly without ever setting a lock at all. Marc Auslander