Hi.

Looks like patch intended to fix FTBFS was wrong. And rendered wrk unusable.

One can't just replace __sync_val_compare_and_swap by
__atomic_compare_exchange without other changes, since former function returns
previous value of the atomic variable, while latter returns a boolean value. 
True for
success. Placing that value into "max" starts a infinite loop if n was larger 
than 1,
which is almost always.

Proposed patch attached.

---
Rinat
diff -urN wrk-4.0.2-prev/src/stats.c wrk-4.0.2/src/stats.c
--- wrk-4.0.2-prev/src/stats.c	2017-08-01 01:35:38.000000000 +0300
+++ wrk-4.0.2/src/stats.c	2017-08-01 01:57:00.900436161 +0300
@@ -25,8 +25,17 @@
     __atomic_fetch_add(&stats->count, 1, __ATOMIC_SEQ_CST);
     uint64_t min = stats->min;
     uint64_t max = stats->max;
-    while (n < min) min = __atomic_compare_exchange(&stats->min, &min, &n, false,__ATOMIC_SEQ_CST,__ATOMIC_SEQ_CST);
-    while (n > max) max = __atomic_compare_exchange(&stats->max, &max, &n, false,__ATOMIC_SEQ_CST,__ATOMIC_SEQ_CST);
+    while (n < min) {
+        __atomic_compare_exchange(&stats->min, &min, &n, false,
+                                  __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
+        min = stats->min;
+    }
+    while (n > max) {
+        __atomic_compare_exchange(&stats->max, &max, &n, false,
+                                  __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
+        max = stats->max;
+    }
+
     return 1;
 }
 

Reply via email to