LWN: Comments on "Lockless patterns: more read-modify-write operations" https://lwn.net/Articles/849237/ This is a special feed containing comments posted to the individual LWN article titled "Lockless patterns: more read-modify-write operations". en-us Wed, 08 Oct 2025 18:46:27 +0000 Wed, 08 Oct 2025 18:46:27 +0000 https://www.rssboard.org/rss-specification lwn@lwn.net Lockless patterns: more read-modify-write operations https://lwn.net/Articles/849946/ https://lwn.net/Articles/849946/ pbonzini <div class="FormattedComment"> Yes, it is.<br> <p> I agree that one should use preexisting APIs; rather than<br> atomic_dec_and_lock the article points to kref_put_lock as the higher-level API that you want to use, I guess to some extent it&#x27;s a matter of taste.<br> </div> Sun, 21 Mar 2021 11:12:56 +0000 Lockless patterns: more read-modify-write operations https://lwn.net/Articles/849937/ https://lwn.net/Articles/849937/ dgc <p>Isn't your put_gadget() example just demonstrating why the atomic_dec_and_lock() primitive exists? <p>Wouldn't it be better to teach people this pattern for atomically grabbing a lock when dropping the last reference to an object as it is much easier to understand and hard to get wrong? <p> <code> <pre> put_gadget() { if (!atomic_dec_and_lock(&amp;g-&gt;refcnt, &amp;lock)) return; list_del(&amp;g-&gt;node); spin_unlock(&amp;lock); } </pre> </code> <p>This is assuming, of course, that an unlocked get side is using atomic_inc_not_zero() to avoid get/put races... <p>-Dave. Sat, 20 Mar 2021 23:48:13 +0000