By: Eric Bron (eric.bron.delete@this.zvisuel.privatefortest.com), December 5, 2014 10:32 am
Room: Moderated Discussions
Gabriele Svelto (gabriele.svelto.delete@this.gmail.com) on December 5, 2014 10:17 am wrote:
> Eric Bron nli (eric.bron.delete@this.zvisuel.com) on December 5, 2014 2:28 am wrote:
> > 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)
>
> Absolutely. I'm all for using what primitives are available instead of ASM, especially now
> that atomic operations are readily available as first class citizens in C/C++ compilers.
even good old C++ is quite expressive and safe enough
as you probably know, a typical CS based lock will look like
class Lock
{
CriticalSection *cs;
public:
Lock (CriticalSection *vCS) : cs(vCS) {if (cs) cs->enter();}
~Lock () {if (cs) cs->leave();}
};
with client code like
{
Lock lock(cs);
// my stuff here, incl. early return or exceptions thrown
}
> Eric Bron nli (eric.bron.delete@this.zvisuel.com) on December 5, 2014 2:28 am wrote:
> > 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)
>
> Absolutely. I'm all for using what primitives are available instead of ASM, especially now
> that atomic operations are readily available as first class citizens in C/C++ compilers.
even good old C++ is quite expressive and safe enough
as you probably know, a typical CS based lock will look like
class Lock
{
CriticalSection *cs;
public:
Lock (CriticalSection *vCS) : cs(vCS) {if (cs) cs->enter();}
~Lock () {if (cs) cs->leave();}
};
with client code like
{
Lock lock(cs);
// my stuff here, incl. early return or exceptions thrown
}