[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: about reference counter
On Fri, Oct 01, 2004 at 05:45:56PM -0400, lml@xxxxxxxxxxxxxxxx wrote:
> > > After that, they canread/write the object at the same time, right? It
> > > sounds like only the reference counter is atomic, while the content of
> > > the object is not protected. Please correct me if I am wrong.
> >
> > Yes, they could both use the object at the same time. But if you need
> > to protect from that, you need a lock, not only a reference count.
>
> So what is the real purpose of using reference counter? It cannot
> protect other members in the object.
You are correct, that is not what a reference counter is for.
> Looks like it is only used to check if the object needed to be freed
> (when the counter is 0)? right?
Yes.
> Can you give an example?
struct urb. When the last user of it is done, it is automatically
cleaned up and freed. struct device, struct kobject, struct
class_device, struct class are all other examples. The kernel is full
of them.
Hope this helps.
greg k-h
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/