- 论坛徽章:
- 11
|
windoze 发表于 2013-10-29 23:16 ![]()
回复 30# zylthinking
39行是常量么?没发现……
乱序了怎么会出问题?
struct lkf_node* head = __sync_lock_test_and_set(&(list->root.next), NULL);
if (head == NULL) {
return NULL;
}
struct lkf_node* next = head->next;
if (next != NULL) {
list->root.next = next;
head->next = head;
return head;
}
依赖 1.
list->root.next = next;
head->next = head;
依赖 next != NULL
依赖 2.
list->root.next 依赖一开始的 struct lkf_node* next = head->next; 而不是 head->next = head; 赋值后的 head->next
若你说依赖2 不存在, 那么int i = 8; int k = i; i = 9 你猜 k 最终的值是哪个?
|
|