https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66842
Bin Fan <bin.x.fan at oracle dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- Component|c |c++ --- Comment #4 from Bin Fan <bin.x.fan at oracle dot com> --- Since I don't see any response from C so far, I change the example to C++ code, and change the category to c++. Could C++ folks take a look? -bash-4.2$ cat c++11_locked_atomics.cpp #include <atomic> using namespace std; #ifndef SIZE #define SIZE 1024 #endif typedef struct { char a[SIZE]; } lock_obj_t; extern "C" { extern void display_nlocks (); } int main() { lock_obj_t v2 = {0}; atomic<lock_obj_t> v1 = ATOMIC_VAR_INIT(v2); v2 = atomic_load (&v1); display_nlocks (); return 0; } gcc -shared -ldl -fPIC libmythread.c -o libmythread.so -g g++ -std=c++11 -latomic c++11_locked_atomics.cpp -DSIZE=2048 -g -L./ -Wl,-rpath=./ -lmythread + LD_PRELOAD=./libmythread.so + a.out pthread_mutex_lock is called 32 times The g++ version is still 4.9.2.