By: Konrad Schwarz (no.spam.delete@this.no.spam), December 5, 2014 3:37 am
Room: Moderated Discussions
Eric Bron nli (eric.bron.delete@this.zvisuel.com) on December 5, 2014 2:28 am wrote:
> >For an unspecified x86 processor:
> >
> >
>
> so using a CriticalSection is generally a better choice than using ASM with lock prefixes, higher level,
> more flexible, and even faster/lower power when heavy contention (thanks to the PAUSE instruction)
>
This is why the monitor (mutex/condition variable) paradigm is so good:
in the uncontended case, lock operations (should) reduce
to not much more than an atomic check and lock of some sort.
If this fails, they can start spinning, or invoke a system call.
> >For an unspecified x86 processor:
> >
> >
MemoryBarrier was measured as taking 20-90 cycles.
> > InterlockedIncrement was measured as taking 36-90 cycles.
> > Acquiring or releasing a critical section was measured as taking 40-100 cycles.
>
> so using a CriticalSection is generally a better choice than using ASM with lock prefixes, higher level,
> more flexible, and even faster/lower power when heavy contention (thanks to the PAUSE instruction)
>
This is why the monitor (mutex/condition variable) paradigm is so good:
in the uncontended case, lock operations (should) reduce
to not much more than an atomic check and lock of some sort.
If this fails, they can start spinning, or invoke a system call.