libcamera: base: thread: Use pthread_self() when setting name

There is a data race between `Thread::start()` writing `Thread::thread_`
and `Thread::startThread()` reading it. Avoid it by using `pthread_self()`
to get the id of the current thread instead of using the `thread_` member.

This is at least the second time this issue occurs:
https://lists.libcamera.org/pipermail/libcamera-devel/2025-January/047954.html

Fixes: 559128b1f1 ("Thread: Add name parameter")
Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
Barnabás Pőcze
2025-11-11 09:34:47 +01:00
parent 559128b1f1
commit 3c2f180600

View File

@@ -292,8 +292,7 @@ void Thread::startThread()
currentThreadData = data_.get();
if (!name_.empty())
pthread_setname_np(thread_.native_handle(),
name_.substr(0, 15).c_str());
pthread_setname_np(pthread_self(), name_.substr(0, 15).c_str());
run();
}