您的位置:首页 > 其它

gcc原子操作,AtomicIntegerT , gcc编译选项(11)

2013-11-06 10:39 369 查看

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的类图



上面的函数都是原子操作的,也就是线程安全的函数。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: