bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [RFC] kern: simple futex for gnumach (version 11)


From: Richard Braun
Subject: Re: [RFC] kern: simple futex for gnumach (version 11)
Date: Fri, 10 Jan 2014 01:59:55 +0100
User-agent: Mutt/1.5.21 (2010-09-15)

On Thu, Jan 09, 2014 at 09:51:51PM +0100, Marin Ramesa wrote:
> On 01/09/2014 05:52:21 PM, Richard Braun wrote:
> >On Thu, Jan 09, 2014 at 05:06:09PM +0100, Marin Ramesa wrote:
> >> Shouldn't the compare be atomic. Maybe I don't understand what
> >> atomic really
> >> means but the GCC manual says this function is. Or is it enough to
> >> hold the lock.
> >
> >From the GCC manual :
> >"These built-in functions perform an atomic compare and swap. That is,
> >if the current value of *ptr is oldval, then write newval into *ptr".
> >So tell us what the point of replacing oldval with itself is.
> 
> I do a swap so it returns true if they are equal.

I'll say it again because it doesn't look like you got it : when I point
something out to you, consider you're wrong, and make the effort to
question your assumptions. You may end up being right at times, but most
often not. Now please, read your code again, then answer the question I
asked : "So tell us what the point of replacing oldval with itself is".

> >In addition, use __sync_val_compare_and_swap please.
> 
> Don't you think it's better this way. The function already
> returns a boolean. What would I do with the contents of *ptr
> before the operation. It doesn't tell me if the swap was
> successful. I would need to introduce a new variable.

Actually it does, but since you probably didn't understand CAS, it's not
so surprising you're thinking that. Now, after reading the code again,
I'm not yet sure how to correctly deal with the previous value, and will
have to read about futexes a bit more. The boolean version should do for
now.

-- 
Richard Braun



reply via email to

[Prev in Thread] Current Thread [Next in Thread]