摘要: 多读多写下,先进后出队列,可以不加锁,下面是实现代码 lifo.h#include "cas.h" #include <stddef.h>struct lifo_node { volatile struct lifo_node *next; };struct lifo { void init() { top = NULL; cnt=0; } void push(lifo_node *node) { struct lifo old_val, new_val; do { old_val = *this; node->next = old_val.top; ne 阅读全文
posted @ 2011-04-06 10:25 napoleon_liu 阅读(2357) 评论(0) 推荐(0) 编辑
摘要: cas.h #if defined(__GNUC__) #if defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP) #define CAS __sync_bool_compare_and_swap #endif //CAS2 #if defined(__x86_64__) #if defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_16... 阅读全文
posted @ 2011-04-06 10:20 napoleon_liu 阅读(2872) 评论(0) 推荐(0) 编辑