Which CPU architectures support Compare And Swap (CAS)?

前端 未结 10 1830
野性不改
野性不改 2020-12-12 15:53

just curious to know which CPU architectures support compare and swap atomic primitives?

10条回答
  •  忘掉有多难
    2020-12-12 16:22

    Intel x86 has this support. IBM in it's Solaris to Linux Porting Guide gives this example:

    bool_t My_CompareAndSwap(IN int *ptr, IN int old, IN int new)
    {
            unsigned char ret;
    
            /* Note that sete sets a 'byte' not the word */
            __asm__ __volatile__ (
                    "  lock\n"
                    "  cmpxchgl %2,%1\n"
                    "  sete %0\n"
                    : "=q" (ret), "=m" (*ptr)
                    : "r" (new), "m" (*ptr), "a" (old)
                    : "memory");
    
            return ret;
    }
    

提交回复
热议问题