Re: Small confusing regarding __atomic_load_n()

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

 



On 18 September 2013 15:54, Jules Colding wrote:
> Hi,
>
> When I do something like:
>
> thread 1:
>
>    int count = 0;
>    int *thread_var = &count;
>
> thread 2:
>
>    __atomic_store_n(thread_var, 7, __ATOMIC_RELEASE);
>
>
> Do I then need to do the following in thread 3?

What are you trying to do?

> thread 3 option 1:
>
>    *thread_var = __atomic_load_n(thread_var, __ATOMIC_ACQUIRE);

This reads the value of *thread_var, returns it, then (non-atomically)
stores it back in *thread_var.  What's the point of that? If you need
the value, you still haven't read it back from *thread_var (and you
may have created a race condition by writing to *thread_var.)


> Or do this suffice?
>
> thread 3 option 2:
>
>    __atomic_load_n(thread_var, __ATOMIC_ACQUIRE);

This loads the value then discards it again.

I think you want:

int var = __atomic_load_n(thread_var, __ATOMIC_ACQUIRE);




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux