Re: MemoryBarrier vs volatile vs lock

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




Normalized results:

baseline = : 1.0
volatile_int = : 0.8990427
Memory Barriers = : 30.83289
VolatileMethods = : 59.72657
locked = : 12.79946
Interlocked = : 2.360716


Notes:
1) volatile field is about the same performance as non volatile
2) interlocked has great performance.
3) locked is faster than memory barrier
4) VolatileRead and VolatileWrite suck. (technically speaking)


Normalizing Daniel's results:
baseline = : 1.0
volatile_int = : 1.2
Memory Barriers = : 50.38
VolatileMethods = : 101.72
locked = : 92.7
Interlocked = : 37.8

5) volatile field still looks great
6) interlocked is a lot slower
7) Memory Barrier and VolatileMethods are about twice as slow
8) locked is 7 times slower and slower than a memory barier


Jon Skeets results:
baseline = 1.0
volatile_int = 1.013137391
Memory Barriers = 7.136038468
VolatileMethods = 16.33100877
locked = 9.045426727
Interlocked =4.450021857

9) Ok volatile still is great.
10) Interlocked performance is much better than Daniel's
11) locked is only marginally slower than MemoryBarrier (not faster as on my
laptop)

12) VolatileRead/Write are slower but not nearly as slow as Daniel and I are
seeing.

I'm surprised to see such a variety.
I'm using Beta 2. No multiprocessor no hyperthreading.

What are each of you using?

.



Relevant Pages

  • Re: x86 i/o management
    ... the hardware access and memory barrier ... The way I would implement volatile is by saying "volatile obviously was ... With all the language lawyering I came to the conclusion that you can't ...
    (comp.arch)
  • Which functions act as memory barriers?
    ... the compiler can optimize and load shared ... Therefore, declaring shared_data as volatile ... And where can I read about this memory barrier concept? ...
    (comp.lang.c)
  • Re: C Programmer Needed
    ... >> buffering messages between two threads. ... >> the compiler this is to mark the array as volatile. ... tion will provide a memory barrier at a volatile access. ... the new Java memory-access semantics that arrived with Java 5, ...
    (comp.programming)
  • Re: volatile and win32 multithreading
    ... Declare it volatile. ... idea that volatile suppresses optimizations and forces the compiler to go to ... Compilers typically don't confer memory barrier ... In addition to providing mutual exclusion, the mutex lock/unlock operations ...
    (microsoft.public.vc.language)
  • Re: Volatile happens before question
    ... Volatile read. ... Synchronization Order ... Two actions can be ordered by a happens-before relationship. ... Reading the volatile field induces synchronization between the threads, ...
    (comp.lang.java.programmer)