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.html
Gcc编译选项
AtomicIntegerT ---muduo库
AtomicIntegerT的类图
上面的函数都是原子操作的,也就是线程安全的函数。