BUG/MEDIUM: thread: use pthread_self() not ha_pthread[tid] in set_affinity
authorWilly Tarreau <w@1wt.eu>
Wed, 12 Mar 2025 14:54:36 +0000 (15:54 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 13 Mar 2025 15:01:04 +0000 (16:01 +0100)
commit77494a9104e6d3ad5d8ca24f2fb343ab2e4b1c13
tree05a5b33abf98d6be3bc3859623d6ad72f0a9a1b1
parent77b340e17d3da9fc78ed113ebe98b2101c10994c
BUG/MEDIUM: thread: use pthread_self() not ha_pthread[tid] in set_affinity

A bug was uncovered by the work on NUMA. It only triggers in the CI
with libmusl due to a race condition. What happens is that the call
to set_thread_cpu_affinity() is done very early in the polling loop,
and that it relies on ha_pthread[tid] instead of pthread_self(). The
problem is that ha_pthread[tid] is only set by the return from
pthread_create(), which might happen later depending on the number of
CPUs available to run the starting thread.

Let's just use pthread_self() here. ha_pthread[] is only used to send
signals between threads, there's no point in using it here.

This can be backported to 2.6.

(cherry picked from commit 12383fd9f5b3614dbffec6260b82659c3c5fd0df)
Signed-off-by: Willy Tarreau <w@1wt.eu>
src/thread.c