- gcc原子操作,AtomicIntegerT , gcc编译选项(11)
-
Gcc原子操作
// 原子自增操作type __sync_fetch_and_add (type *ptr, type value)// 原子比较和交换(设置)操作type __sync_val_compare_and_swap (type *ptr, type oldval type newval)bool __sync_bool_compare_and_swap (type *ptr, type oldval type newval)// 原子赋值操作type __sync_lock_test_and_set (type *ptr, type value)使用这些原子性操作,编译的时候需要加-march=cpu-type无锁队列实现http://coolshell.cn/articles/8239. htmlGcc编译选项AtomicIntegerT ---muduo库AtomicIntegerT的类图上面的函数都是原子操作的,也就是线程安全的函数。