question on memory fence

question on memory fence

take Compare and Swap as en example:

free(coid * newhead)



oldhead = next;

newhead->next = next;

//asm volatile("mfence":::"memory");


'next' is the freelist's head,the function will put 'next' point to newhead, and nexhead->next point to original next,butI found sometimes newhead->next doesn't update with 'next'

is it relevant to memory fence?

BTW, I only tested it with gcc

1 post / 0 new
For more complete information about compiler optimizations, see our Optimization Notice.