[ntp:hackers] [Gpsd-dev] Single-writer/many-reader consistency

Håkan Johansson f96hajo at chalmers.se
Sat Mar 26 16:04:48 UTC 2011


> I've done some research, it turns out that both gcc (from v4.something)
> and MS Visual C (from before V2005) have builtin support for memory
> barriers:
>
> http://en.wikipedia.org/wiki/Memory_barrier
> http://en.wikipedia.org/wiki/Memory_ordering
>
> In the latter there's a nice chart showing all the ways various
> architectures relaxes the strict program order memory consistency.
>
> Quoting the second link above:
> GCC since version 4.1.0 and intel c++ compiler have special builtin for
> calling full hardware memory barrier:
>
> __sync_synchronize().

Unfortunately, not:

sync.c:

int test()
{
   __sync_synchronize();
}

htj at org-pc51:~/sw$ gcc --version
gcc (Debian 4.3.2-1.1) 4.3.2
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR 
PURPOSE.

htj at org-pc51:~/sw$ gcc -O3 -o sync.o -c sync.c
htj at org-pc51:~/sw$ objdump -d sync.o

sync.o:     file format elf64-x86-64

Disassembly of section .text:

0000000000000000 <test>:
    0:	c3                   	retq

No memory barriers...  (-O3 had no difference, just made it shorter)

Also see 
http://stackoverflow.com/questions/982129/what-does-sync-synchronize-do
third answer 'Dec 5 '09 at 10:47'

"Note not implemented on all platforms and silently does nothing when not 
implemented. Found this out the hard way on ARM..."

Cute?

Cheers,
Håkan


More information about the hackers mailing list