Answer by interjay for Why does __sync_add_and_fetch work for a 64 bit...
The reading of the variable in 0x804855a and 0x804855f does not need to be atomic. Using the compare-and-swap instruction to increment looks like this in pseudocode:oldValue = *dest; // non-atomic:...
View ArticleAnswer by Necrolis for Why does __sync_add_and_fetch work for a 64 bit...
The initial read with 2 separate mov instructions is not atomic, but it's not in the loop. @interjay's answer explains why this is fine.Fun fact: the read done by cmpxchg8b would be atomic even without...
View ArticleWhy does __sync_add_and_fetch work for a 64 bit variable on a 32 bit system?
Consider the following condensed code:/* Compile: gcc -pthread -m32 -ansi x.c */#include <stdio.h>#include <inttypes.h>#include <pthread.h>static volatile uint64_t v = 0;void *func...
View Article
More Pages to Explore .....