Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Linux: Kernel

Unreliable Guide to Locking - Addition?

 

 

Linux kernel RSS feed   Index | Next | Previous | View Threaded


kedars at gmail

Aug 8, 2005, 6:11 AM

Post #1 of 2 (255 views)
Permalink
Unreliable Guide to Locking - Addition?

Hi Rusty,

I was going through the splendidly written document,
"Unreliable Guide to Locking". I thought of something that should be
mentioned in the section "Using Atomic Operations For The Reference
Count" (link : http://www.kernel.org/pub/linux/kernel/people/rusty/kernel-locking/x352.html#EXAMPLES-REFCNT-ATOMIC)

I guess, probably the section should also mention that
"
There is one race condition while using atomic_t, which is as follows :

* The refcount of the object is "1".

* Process A tries to perform atomic_dec_and_test(), gets "0" and hence
performs a kfree() on the object.

* Process B tries to perform atomic_inc() on the object.

* It may so happen that the atomic_inc() of Process B is called after
atomic_dec_and_test(), but before the kfree() call, which is a race
condition.

Usually, this race condition is avoided as:
when the last atomic_dec_and_test() (the last == the one which
returns 0) is being called on the object, the object is usually not
accessible to others (list_del()) and hence the simultaneous
atomic_inc() call never occurs.
"

Do you think this race condition should be included in the document?

Thanks,
Kedar.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo[at]vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/


rusty at rustcorp

Aug 8, 2005, 7:35 PM

Post #2 of 2 (232 views)
Permalink
Re: Unreliable Guide to Locking - Addition? [In reply to]

On Mon, 2005-08-08 at 18:41 +0530, Kedar Sovani wrote:
> when the last atomic_dec_and_test() (the last == the one which
> returns 0) is being called on the object, the object is usually not
> accessible to others (list_del()) and hence the simultaneous
> atomic_inc() call never occurs.

Yes, a reference count must count references. Of course, you can get
around with with "atomic_dec_and_lock", but I hate that primitive as it
has scalability issues (it can't be translated to RCU).

I'll look and see if I can make this requirement explicit.

Thanks!
Rusty.
--
A bad analogy is like a leaky screwdriver -- Richard Braakman

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo[at]vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Linux kernel RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.