GLIB:g_atomic_int_get变为NO-OP?

在更大的代码片段中,我注意到glib中的g_atomic_ *函数没有达到我的预期,所以我写了这个简单的例子:
#include <stdlib.h>
#include "glib.h"
#include "pthread.h"
#include "stdio.h"

void *set_foo(void *ptr) {
  g_atomic_int_set(((int*)ptr), 42);
  return NULL;
}

int main(void) {
  int foo = 0;
  pthread_t other;

  if (pthread_create(&other, NULL, set_foo, &foo)== 0) {
    pthread_join(other, NULL);
    printf("Got %dn", g_atomic_int_get(&foo));
  } else {
    printf("Thread did not runn");
    exit(1);
  }
}
当我使用GCC的'-E'选项编译它时(在预处理后停止),我注意到对g_atomic_int_get(&amp; foo)的调用已变为:
(*(&foo))
和g_atomic_int_set(((int *)ptr),42)变为:
((void) (*(((int*)ptr)) = (42)))
显然,我期待一些原子比较和交换操作,而不仅仅是简单(线程不安全)的分配。我究竟做错了什么? 作为参考,我的编译命令如下所示:
gcc -m64 -E -o foo.E `pkg-config --cflags glib-2.0` -O0 -g foo.c
    
已邀请:
您所使用的体系结构不需要内存整数设置/获取操作的内存屏障,因此转换有效。 这是它的定义:http://git.gnome.org/browse/glib/tree/glib/gatomic.h#n60 这是一件好事,因为否则你需要为每个原子操作锁定一个全局互斥锁。     

要回复问题请先登录注册