From: Christopher Faulet Date: Wed, 2 May 2018 14:58:40 +0000 (+0200) Subject: BUG/MEDIUM: threads: Fix the sync point for more than 32 threads X-Git-Tag: v1.9-dev1~277 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=148b16e1ceb819dfcef4c45828121d9cd7474b35;p=thirdparty%2Fhaproxy.git BUG/MEDIUM: threads: Fix the sync point for more than 32 threads In the sync point, to know if a thread has requested a synchronization, we call the function thread_need_sync(). It should return 1 if yes, otherwise it should return 0. It is intended to return a signed integer. But internally, instead of returning 0 or 1, it returns 0 or tid_bit (threads_want_sync & tid_bit). So, tid_bit is casted in integer. For the first 32 threads, it's ok, because we always check if thread_need_sync() returns something else than 0. But this is a problem if HAProxy is started with more than 32 threads, because for threads 33 to 64 (so for tid 32 to 63), their tid_bit casted to integer are evaluated to 0. So the sync point does not work for more than 32 threads. Now, the function thread_need_sync() respects its contract, returning 0 or 1. the function thread_no_sync() has also been updated to avoid any ambiguities. This patch must be backported in HAProxy 1.8. --- diff --git a/src/hathreads.c b/src/hathreads.c index 839b08696b..0d690f3831 100644 --- a/src/hathreads.c +++ b/src/hathreads.c @@ -82,7 +82,7 @@ void thread_want_sync() /* Returns 1 if no thread has requested a sync. Otherwise, it returns 0. */ int thread_no_sync() { - return (threads_want_sync == 0); + return (threads_want_sync == 0UL); } /* Returns 1 if the current thread has requested a sync. Otherwise, it returns @@ -90,7 +90,7 @@ int thread_no_sync() */ int thread_need_sync() { - return (threads_want_sync & tid_bit); + return ((threads_want_sync & tid_bit) != 0UL); } /* Thread barrier. Synchronizes all threads at the barrier referenced by