Linux-man Archive on lore.kernel.org
 help / color / Atom feed
From: Ponnuvel Palaniyappan <pponnuvel@gmail.com>
To: mtk.manpages@gmail.com
Cc: linux-man@vger.kernel.org
Subject: [patch] futex.2: Fix a bug in the example
Date: Wed, 8 Jan 2020 09:09:48 +0000
Message-ID: <CAOL8xrWJgOLpwx97vOvZ7dTvH9D-1=WvzRNi_a4Sd_BbT850Fg@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 256 bytes --]

The man page contains a trivial bug that's discussed here:
https://stackoverflow.com/q/59628958

The patch was against latest master (commit:
f7d3e6aac109528e6f22f7c9cc5439a6ceeaa7de) and tested on Ubuntu
4.15.0-72-generic kernel.

-- 
Regards,
Ponnuvel P

[-- Attachment #2: 0001-futex.2-Fix-a-bug-in-the-example.patch --]
[-- Type: text/x-patch, Size: 1194 bytes --]

From 3ab2e9d969c63a4f6cbca415a6a3ac1763449fd3 Mon Sep 17 00:00:00 2001
From: Ponnuvel Palaniyappan <pponnuvel@gmail.com>
Date: Wed, 8 Jan 2020 09:03:07 +0000
Subject: [PATCH] futex.2: Fix a bug in the example

---
 man2/futex.2 | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/man2/futex.2 b/man2/futex.2
index 8a003e2be..01b36cac3 100644
--- a/man2/futex.2
+++ b/man2/futex.2
@@ -1797,8 +1797,8 @@ fwait(int *futexp)
     while (1) {
 
         /* Is the futex available? */
-        const int zero = 0;
-        if (atomic_compare_exchange_strong(futexp, &zero, 1))
+        const int one = 1;
+        if (atomic_compare_exchange_strong(futexp, &one, 0))
             break;      /* Yes */
 
         /* Futex is not available; wait */
@@ -1820,8 +1820,8 @@ fpost(int *futexp)
 
     /* atomic_compare_exchange_strong() was described in comments above */
 
-    const int one = 1;
-    if (atomic_compare_exchange_strong(futexp, &one, 0)) {
+    const int zero = 0;
+    if (atomic_compare_exchange_strong(futexp, &zero, 1)) {
         s = futex(futexp, FUTEX_WAKE, 1, NULL, NULL, 0);
         if (s  == \-1)
             errExit("futex\-FUTEX_WAKE");
-- 
2.17.1


             reply index

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-08  9:09 Ponnuvel Palaniyappan [this message]
2020-01-10 20:31 ` Michael Kerrisk (man-pages)

Reply instructions:

You may reply publically 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='CAOL8xrWJgOLpwx97vOvZ7dTvH9D-1=WvzRNi_a4Sd_BbT850Fg@mail.gmail.com' \
    --to=pponnuvel@gmail.com \
    --cc=linux-man@vger.kernel.org \
    --cc=mtk.manpages@gmail.com \
    /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

Linux-man Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-man/0 linux-man/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-man linux-man/ https://lore.kernel.org/linux-man \
		linux-man@vger.kernel.org
	public-inbox-index linux-man

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-man


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git