This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: atomic_thread_fence() semantics


On 19 October 2017 at 12:58, Mattias Rönnblom wrote:
> Hi.
>
> I have this code:
>
> #include <stdatomic.h>
>
> int ready;
> int message;
>
> void send_x4711(int m) {
>     message = m*4711;
>     atomic_thread_fence(memory_order_release);
>     ready = 1;
> }
>
> When I compile it with GCC 7.2 -O3 -std=c11 on x86_64 it produces the
> following code:
>
> send_x4711:
> .LFB0:
> .LVL0:
>         imul    edi, edi, 4711
> .LVL1:
>         mov     DWORD PTR ready[rip], 1
>         mov     DWORD PTR message[rip], edi
>         ret
>
> I expected the store to 'message' and 'ready' to be in program order.
>
> Did I misunderstand the semantics of
> atomic_thread_fence+memory_order_release?

There are no atomic operations on atomic objects here, so the fence
doesn't synchronize with anything.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]