- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
Just a quick question regarding memory fences in C.
What exactly is the difference (if any) between:
__sync_synchronize();
asm volatile("":::"memory");
Just a quick question regarding memory fences in C.
What exactly is the difference (if any) between:
__sync_synchronize();
asm volatile("":::"memory");
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
asm volatile("":::"memory"); merely prevents the compiler's optimizer from rearranging your code --- reads and writes that appear in source before that asm block must appear as CPU instructions before that asm block, and reads and writes that appear in source after that asm block must appear as CPU instructions after that asm block. The CPU may still reorder these reads and writes, and they may become visible to other CPUs in the system out of order (but constrained by the CPU memory model).
__sync_synchronize() will generate a suitable CPU instruction to generate a memory fence. On Intel CPUs this may be an MFENCE instruction, or a LOCKed instruction such as XCHG. This has the additional consequence of imposing visibility constraints on the memory accesses at the CPU level.
__sync_synchronize() will generate a suitable CPU instruction to generate a memory fence. On Intel CPUs this may be an MFENCE instruction, or a LOCKed instruction such as XCHG. This has the additional consequence of imposing visibility constraints on the memory accesses at the CPU level.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page