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

Re: about reference counter



On Fri, Oct 01, 2004 at 03:50:56PM -0400, lml@xxxxxxxxxxxxxxxx wrote:
> Hi,
> 
> I am not sure how the reference counter can protect the data by just
> checking the number of usage. For example, one thread gets the object
> and increases the counter, while another can get the same object at
> the same time. If there is no locking, how can the reference counter
> solve the race contention.
> 
> Or may be I missed some important part.

You did.  Your reference count needs to be an atomic value.  Just use a
struct kref, it handles all of the logic for you.

greg k-h

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/