cs system call on RS/6000

marc at arnor.uucp marc at arnor.uucp
Tue Dec 11 00:33:37 AEST 1990


"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



More information about the Comp.unix.aix mailing list