TestAndSet

int xchg(int *table, int new) {
    int old = *table; 
    *table = new;
    return old;
}