Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 15 Aug 2006 12:01:26 -0400
From:      John Baldwin <jhb@freebsd.org>
To:        Divacky Roman <xdivac02@stud.fit.vutbr.cz>
Cc:        Roman Divacky <rdivacky@freebsd.org>, Perforce Change Reviews <perforce@freebsd.org>
Subject:   Re: PERFORCE change 104029 for review
Message-ID:  <200608151201.27169.jhb@freebsd.org>
In-Reply-To: <20060815154956.GB60482@stud.fit.vutbr.cz>
References:  <200608151407.k7FE7Lj5095567@repoman.freebsd.org> <200608151127.54902.jhb@freebsd.org> <20060815154956.GB60482@stud.fit.vutbr.cz>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tuesday 15 August 2006 11:49, Divacky Roman wrote:
> On Tue, Aug 15, 2006 at 11:27:54AM -0400, John Baldwin wrote:
> > On Tuesday 15 August 2006 10:07, Roman Divacky wrote:
> > > http://perforce.freebsd.org/chv.cgi?CH=104029
> > > 
> > > Change 104029 by rdivacky@rdivacky_witten on 2006/08/15 14:06:41
> > > 
> > > 	Protect against racing concurent creation in futex_get()
> > > 	
> > > 	Pointed out by: jhb
> > > 
> > > Affected files ...
> > > 
> > 
> .. //depot/projects/soc2006/rdivacky_linuxolator/compat/linux/linux_futex.c#24 
> > edit
> > > 
> > > Differences ...
> > > 
> > > 
> > 
==== //depot/projects/soc2006/rdivacky_linuxolator/compat/linux/linux_futex.c#24 
> > (text+ko) ====
> > > 
> > > @@ -342,13 +342,13 @@
> > >  	if (locked == FUTEX_UNLOCKED)
> > >     	   	FUTEX_UNLOCK;
> > >  
> > > +	if (locked == FUTEX_UNLOCKED)
> > > +   	   	FUTEX_LOCK;
> > 
> > Looks like you should collapse the lock/unlock.  However, it's probably 
best 
> > to use mutexes instead of sx locks, and to instead do something like this:
>  
> the lock here IS a mutex...
>  
> > 	lock();
> > 	if (item in list) {
> > 		item->ref++;
> > 		unlock();
> > 		return (item);
> > 	}
> > 	unlock();
> > 
> > 	new_item = new_item();
> > 
> > 	lock();
> > 	if (item in list) {
> > 		item->ref++;
> > 		unlock();
> > 		free(new_item);
> > 		return (item);
> > 	}
> > 	insert new_item
> > 	new_item->ref++;
> > 	unlock();
> > 	return (new_item)
> 
> isnt this exactly what I am doing in later revision?

No, you aren't doing the second 'if (item in list)' test to see if some other 
thread already added a futex for that uaddr and if so free the one you just 
created and return the one in the list instead.

-- 
John Baldwin



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200608151201.27169.jhb>