How to do proper locking

John Baldwin jhb at FreeBSD.org
Wed Aug 3 17:26:39 GMT 2005


On Tuesday 02 August 2005 06:23 pm, Hans Petter Selasky wrote:
> Hi,
>
> I am looking for a safe way to access structures that can be freed. The
> solution I am looking for must not:
>
> - hinder scaleability
> - lead to use of a single lock
> - lead to lock order reversal

These aren't a very clear set of requirements.  Note that you can't hold a 
lock across malloc(), so your allocation code isn't safe.  You can try taking 
at look at some existing refcounted structures such as ucreds, p_args, etc. 
or looking at structures held in a global list like proc.  What actual 
problem are you trying to solve?  How does code obtain references to 
my_struct objects?  Are they hung off another object that has a lock?  Are 
they in a global list?

-- 
John Baldwin <jhb at FreeBSD.org>  <><  http://www.FreeBSD.org/~jhb/
"Power Users Use the Power to Serve"  =  http://www.FreeBSD.org


More information about the freebsd-hackers mailing list