Discussions of the Parallel Programming book
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: Imre Palik <imrep.amz@gmail.com>
Cc: perfbook@vger.kernel.org
Subject: Re: counting examples
Date: Thu, 5 Jul 2018 16:05:41 -0700	[thread overview]
Message-ID: <20180705230541.GV3593@linux.vnet.ibm.com> (raw)
In-Reply-To: <CAFMy-Rm--uJjqAfFxdbJfuNd-XVsDm+Fh_jx1kGNaojgTgEWKg@mail.gmail.com>

On Thu, Jul 05, 2018 at 10:09:49PM +0200, Imre Palik wrote:
> Hi All,
> 
> first of all, thanks for the great book.

On behalf of all of its contributors, glad you like it!

> I have some doubts about some of the counting examples.  Namely, those
> that implement inc_count() as a simple increment operation.  If there
> is nothing to restrain the compiler/linker, they can possibly merge
> several increments together, or optionally keep the counter value in a
> register.
> 
> Of course, this won't happen with counttorture, because of the
> barrier() in the loop.  But I wonder if that barrier() should be part
> of inc_count() instead.  What do you think?

I actually put this on my todo list as a results of the C++ discussion,
but given that I am in the process of (almost) rewriting Linux-kernel
RCU, it will take time to get to it.  So if you are interested, I would
welcome a patch that added READ_ONCE() and WRITE_ONCE as appropriate.

If you are curious about the historical perspective, some of the counter
code predates ACCESS_ONCE() -- let alone READ_ONCE() and WRITE_ONCE()
-- in the Linux kernel.  Compilers have gotten more aggressive over
the decades.  ;-)

							Thanx, Paul


      reply	other threads:[~2018-07-05 23:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-05 20:09 counting examples Imre Palik
2018-07-05 23:05 ` Paul E. McKenney [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180705230541.GV3593@linux.vnet.ibm.com \
    --to=paulmck@linux.vnet.ibm.com \
    --cc=imrep.amz@gmail.com \
    --cc=perfbook@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox