LWN.net Logo

Advertisement

E-Commerce & credit card processing - the Open Source way!

Advertise here

Problem with ex 2 ?

Problem with ex 2 ?

Posted Dec 23, 2007 23:23 UTC (Sun) by xav (subscriber, #18536)
Parent article: What is RCU, Fundamentally?

It looks to me that example 2 is wrong: access to p is unlocked, so it can changed under its
feet if preempted: *q = *p can access freed memory.


(Log in to post comments)

Problem with ex 2 ?

Posted Dec 27, 2007 18:57 UTC (Thu) by PaulMcKenney (subscriber, #9624) [Link]

Indeed!  As with the preceding example, there must be some sort of mutual exclusion in play,
and as in the preceding example, this mutual exclusion is not shown explicitly.

One approach, as you say, would be to add locking, perhaps similar to that described in the
answer to Quick Quiz 4 (but for the deletion example).  Another approach would be to hold a
mutex (in the old style, "semaphore") across the entire code segment.  Yet a third approach
would be to permit only a single designated task to do updates (in which case the code would
remain as is).  There are other approaches as well.

In any case, I am glad to see that people are sensitized to the need for mutual exclusion in
parallel code!

Copyright © 2008, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds