[patch] futex.2: Fix a bug in the example

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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
From 3ab2e9d969c63a4f6cbca415a6a3ac1763449fd3 Mon Sep 17 00:00:00 2001
From: Ponnuvel Palaniyappan <pponnuvel@xxxxxxxxx>
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


[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux