memory barrier and atomic_t on linux
Recently, I am reading some Linux kernel space codes, I see this uint64_t used; uint64_t blocked; used = atomic64_read(&g_variable->used); //#1 barrier(); //#2 blocked = atomic64_read(&g_variable->blocked); //#3 What is the semantics of this code snippet? Does it make sure #1 executes before #3 by #2. But I am a litter bit confused, becasue #A In 64 bit platform, atomic64_read macro is expanded to used = (&g_variable->used)->counter // where counter is volatile. In 32 bits platform, it was converted to use lock cmpxchg8b . I assume these two have the same semantic, and for 64 bits version, I