Thin lock vs. Futex
Jb
jb at nowhere.com
Tue Sep 2 13:12:23 PDT 2008
"Bartosz Milewski" <bartosz at relisoft.com> wrote in message
news:g9jvui$nbs$1 at digitalmars.com...
> As promised, I posted a blog comparing the thin lock to futex. Please vote
> it on reddit: http://www.reddit.com/comments/6z4sv/ .
Early on you say this...
"Unlock tests if the futex variable is equal to one (we are the owner, and
nobody is waiting). If true, it sets it to zero. This is the fast-track
common-case execution that doesn't make any futex calls whatsoever."
But the futex code you list later in the blog does this....
// we own the lock, so it's either 1 or 2
if (atomic_decrement(&_word) != 1)
So does the futex actualy need/use an atomic for unlocking?
If it does then that makes it a great deal slower than a thin lock as that
typicaly doesnt require an atomic for the unlock. As im sure you're aware,
CAS and such like cost around 120..160 cycles on most cpus, so having an
algorythm that cuts their usage in half is a big avantage.
So I'd be touting that as good reason to use thin locks. :-)
More information about the Digitalmars-d
mailing list