From: Junchang Wang <junchangwang@gmail.com>
To: perfbook@vger.kernel.org
Cc: Junchang Wang <junchangwang@gmail.com>
Subject: [PATCH 2/2] count_stat_eventual: Add READ_ONCE() to protect global shared variable stopflag
Date: Thu, 11 May 2017 23:03:42 +0800 [thread overview]
Message-ID: <1494515022-30278-3-git-send-email-junchangwang@gmail.com> (raw)
In-Reply-To: <1494515022-30278-1-git-send-email-junchangwang@gmail.com>
Signed-off-by: Junchang Wang <junchangwang@gmail.com>
---
CodeSamples/count/count_stat_eventual.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/CodeSamples/count/count_stat_eventual.c b/CodeSamples/count/count_stat_eventual.c
index cbde4aa..2caebfd 100644
--- a/CodeSamples/count/count_stat_eventual.c
+++ b/CodeSamples/count/count_stat_eventual.c
@@ -40,15 +40,15 @@ void *eventual(void *arg)
int t;
unsigned long sum;
- while (stopflag < 3) {
+ while (READ_ONCE(stopflag) < 3) {
sum = 0;
for_each_thread(t)
sum += READ_ONCE(per_thread(counter, t));
WRITE_ONCE(global_count, sum);
poll(NULL, 0, 1);
- if (stopflag) {
+ if (READ_ONCE(stopflag)) {
smp_mb();
- stopflag++;
+ WRITE_ONCE(stopflag, READ_ONCE(stopflag) + 1);
}
}
return NULL;
@@ -66,8 +66,9 @@ void count_init(void)
void count_cleanup(void)
{
- stopflag = 1;
- while (stopflag < 3)
+ WRITE_ONCE(stopflag, 1);
+ smp_mb();
+ while (READ_ONCE(stopflag) < 3)
poll(NULL, 0, 1);
smp_mb();
}
--
2.7.4
next prev parent reply other threads:[~2017-05-11 15:04 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-11 15:03 [PATCH 0/2] Use READ_ONCE() and WRITE_ONCE in count_stat_eventual.c Junchang Wang
2017-05-11 15:03 ` [PATCH 1/2] count_stat_eventual: Switch from ACCESS_ONCE() to READ_ONCE()/WRITE_ONCE() Junchang Wang
2017-05-13 12:04 ` Akira Yokosawa
2017-05-13 12:45 ` Paul E. McKenney
2017-05-13 13:31 ` Junchang Wang
2017-05-13 22:57 ` Paul E. McKenney
2017-05-13 14:37 ` Akira Yokosawa
2017-05-13 22:56 ` Paul E. McKenney
2017-05-14 0:58 ` Akira Yokosawa
2017-05-14 1:31 ` Akira Yokosawa
2017-05-14 4:20 ` Paul E. McKenney
2017-05-14 13:56 ` Junchang Wang
2017-05-14 15:15 ` Akira Yokosawa
2017-05-15 0:31 ` Paul E. McKenney
2017-05-15 14:35 ` Akira Yokosawa
2017-05-16 4:16 ` Paul E. McKenney
2017-05-11 15:03 ` Junchang Wang [this message]
2017-05-14 10:57 ` [PATCH 2/2] count_stat_eventual: Add READ_ONCE() to protect global shared variable stopflag Akira Yokosawa
2017-05-14 13:28 ` Junchang Wang
2017-05-14 22:57 ` Akira Yokosawa
2017-05-16 13:14 ` Junchang Wang
2017-05-11 16:51 ` [PATCH 0/2] Use READ_ONCE() and WRITE_ONCE in count_stat_eventual.c Paul E. McKenney
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=1494515022-30278-3-git-send-email-junchangwang@gmail.com \
--to=junchangwang@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.