g_atomic_pointer*



Hi,

I need to use an atomic pointer for my app. The documentation for the glib
atomic operations is not exactly helpful.

Anyway, I wrote a test program:

----8<----
/* atomic.c */
#include <glib.h>
int main()
{
    char* myptr = 0;
    char* str = "Hello";
    g_atomic_pointer_set(&myptr, str);
    char* p = g_atomic_pointer_get(&myptr);
    return 0;
}
----8<----

I had to use the output of

gcc `pkg-config --cflags glib-2.0` atomic.c -E

to understand what was meant to be used as the parameters. Anyway, the
output of this does not look at all atomic: (not that i'm any expert)

----8<----
...
# 4 "atomic.c" 2

int main()
{
    char* myptr = 0;
    char* str = "Hello";
    ((void) (*(&myptr) = (str)));
    char* p = ((gpointer)*(&myptr));
    return 0;
}
----8<----

This is on a x86_64, running Gentoo, glib-2.20.5.

I don't know if I've got the idea right for how these functions are
supposed to be used. Any ideas?

Cheers,
james.





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]