From: linux@arm.linux.org.uk (Russell King - ARM Linux)
To: linux-arm-kernel@lists.infradead.org
Subject: Problems with semaphores, mutexes, and atomic?
Date: Mon, 20 Jun 2011 09:27:29 +0100 [thread overview]
Message-ID: <20110620082729.GA26089@n2100.arm.linux.org.uk> (raw)
In-Reply-To: <BANLkTikwGgrK0FFiee1a8PvDicJa-bUedg@mail.gmail.com>
On Sun, Jun 19, 2011 at 11:39:49PM -0700, Dave Hylands wrote:
> Each thread performs the loop a number of times, and at the end the
> count often doesn't have the expected value if the locks were in fact
> atomic.
>
> Typical output looks like:
>
> 192.168.0.50 ~ # modprobe test-mutex
> [ 26.220000] Testing mutex...
> [ 26.230000] Launching threads ..........
> [ 26.300000] Waiting for threads to finish ..........
> [ 26.310000] counter = 999888 FAIL
> [ 26.310000] Testing semaphore...
> [ 26.310000] Launching threads ..........
> [ 26.440000] Waiting for threads to finish ..........
> [ 27.810000] counter = 999575 FAIL
> [ 27.810000] Testing atomic...
> [ 27.820000] Launching threads ..........
> [ 28.030000] Waiting for threads to finish ..........
> [ 28.040000] counter = 9910929 FAIL
The answer is quite simple. You're not waiting for all the threads to
finish. The first down(&thread_wait) will succeed, so the values you're
getting above could be up to 100000 (NUM_ATOMIC_ITER) out. And they
are.
next prev parent reply other threads:[~2011-06-20 8:27 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-20 6:39 Problems with semaphores, mutexes, and atomic? Dave Hylands
2011-06-20 7:20 ` saeed bishara
2011-06-20 7:44 ` Dave Hylands
2011-06-20 8:03 ` Arnd Bergmann
2011-06-20 8:21 ` Dave Hylands
2011-06-20 8:34 ` Arnd Bergmann
2011-06-20 9:07 ` Dave Hylands
2011-06-20 8:27 ` Russell King - ARM Linux [this message]
2011-06-20 8:58 ` Dave Hylands
2013-07-16 7:11 ` Hesham Mahmoud
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=20110620082729.GA26089@n2100.arm.linux.org.uk \
--to=linux@arm.linux.org.uk \
--cc=linux-arm-kernel@lists.infradead.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;
as well as URLs for NNTP newsgroup(s).