[Development] QBasicMutex::lockInternal() race condition?

Olivier Goffart olivier at woboq.com
Fri Sep 21 01:18:32 CEST 2012


On Thursday 20 September 2012 19:07:26 Thiago Macieira wrote:
> On quinta-feira, 20 de setembro de 2012 16.50.18, Tony Van Eerd wrote:
> > But we already did an acquire earlier when we got the d_ptr the first
> > time.  All our instructions on id and waiters happens after that.
> > 
> > If we are worried about ABA on the d_ptr, hmmm, I'd need to think about
> > that.
> 
> Right, we have an acquire before. Which means that, if the comparison
> succeeds, we've already acquired the fields that don't change.
> 
> If the comparison fails, however, we need the acquire because of the id. It
> could have changed. Maybe the Acquire should be moved there, which means the
> id should be an atomic too.

Not really, the id can't change.
The id is only set once when the QMutexPrivate is used for the first time.
(And that change has already been aquired for a long time)

Acquire is uneccessary. 

It was added in commit 5bfeab87 when the uses of the operator were removed. I 
guess a lot of the barers where added for safety, because it would have been 
too much work to look in so many place which one were necessary.

-- 
Olivier

Woboq - Qt services and support - http://woboq.com



More information about the Development mailing list