[{"id":36765,"web_url":"https://patchwork.libcamera.org/comment/36765/","msgid":"<d994e386-3f30-4016-8053-5ca8a70866f5@ideasonboard.com>","date":"2025-11-11T11:11:26","subject":"Re: [PATCH v1] libcamera: base: thread: Use `pthread_self()` when\n\tsetting name","submitter":{"id":156,"url":"https://patchwork.libcamera.org/api/people/156/","name":"Dan Scally","email":"dan.scally@ideasonboard.com"},"content":"Hi Barnabás\n\nOn 11/11/2025 08:41, Barnabás Pőcze wrote:\n> There is a data race between `Thread::start()` writing `Thread::thread_`\n> and `Thread::startThread()` reading it. Avoid it by using `pthread_self()`\n> to get the id of the current thread instead of using the `thread_` member.\n> \n> This is at least the second time this issue occurs:\n> https://lists.libcamera.org/pipermail/libcamera-devel/2025-January/047954.html\n> \n> Fixes: 559128b1f1b3cf (\"Thread: Add name parameter\")\n> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n> ---\nGood spot:\n\nReviewed-by: Daniel Scally <dan.scally@ideasonboard.com>\n\n>   src/libcamera/base/thread.cpp | 3 +--\n>   1 file changed, 1 insertion(+), 2 deletions(-)\n> \n> diff --git a/src/libcamera/base/thread.cpp b/src/libcamera/base/thread.cpp\n> index 39209ec8ad..b94a3d7490 100644\n> --- a/src/libcamera/base/thread.cpp\n> +++ b/src/libcamera/base/thread.cpp\n> @@ -292,8 +292,7 @@ void Thread::startThread()\n>   \tcurrentThreadData = data_.get();\n>   \n>   \tif (!name_.empty())\n> -\t\tpthread_setname_np(thread_.native_handle(),\n> -\t\t\t\t   name_.substr(0, 15).c_str());\n> +\t\tpthread_setname_np(pthread_self(), name_.substr(0, 15).c_str());\n>   \n>   \trun();\n>   }","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 853DAC3241\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 11 Nov 2025 11:11:32 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D83B6606D5;\n\tTue, 11 Nov 2025 12:11:31 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id EB47F606A0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 11 Nov 2025 12:11:29 +0100 (CET)","from [192.168.0.43]\n\t(cpc141996-chfd3-2-0-cust928.12-3.cable.virginm.net [86.13.91.161])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id E912C22B;\n\tTue, 11 Nov 2025 12:09:30 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"f9IsGTvA\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1762859371;\n\tbh=ar6Ktd+O+cUDS+EeWtWYAUHgyw6J19FAdD+JOAZZEdY=;\n\th=Date:Subject:To:References:From:In-Reply-To:From;\n\tb=f9IsGTvA4JrUen8hyrAPgHlJy0DiYEl89KHjeKdDDNXLZteNPHDaKXbCdtcWO2IDN\n\tevJgYRWND2cdgr/rwODuYOB80Ej30Ol9ipf11RnEvqqCmxfORT7jdOfz0NlnR3edOK\n\ts1BsM2cuYS+MnMj5D9O38zhM5skkq5qhos5CvPng=","Message-ID":"<d994e386-3f30-4016-8053-5ca8a70866f5@ideasonboard.com>","Date":"Tue, 11 Nov 2025 11:11:26 +0000","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v1] libcamera: base: thread: Use `pthread_self()` when\n\tsetting name","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20251111084133.2292217-1-barnabas.pocze@ideasonboard.com>","Content-Language":"en-US","From":"Dan Scally <dan.scally@ideasonboard.com>","In-Reply-To":"<20251111084133.2292217-1-barnabas.pocze@ideasonboard.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"8bit","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":36766,"web_url":"https://patchwork.libcamera.org/comment/36766/","msgid":"<20251111112626.GA16414@pendragon.ideasonboard.com>","date":"2025-11-11T11:26:26","subject":"Re: [PATCH v1] libcamera: base: thread: Use `pthread_self()` when\n\tsetting name","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Tue, Nov 11, 2025 at 09:41:33AM +0100, Barnabás Pőcze wrote:\n> There is a data race between `Thread::start()` writing `Thread::thread_`\n> and `Thread::startThread()` reading it. Avoid it by using `pthread_self()`\n> to get the id of the current thread instead of using the `thread_` member.\n> \n> This is at least the second time this issue occurs:\n> https://lists.libcamera.org/pipermail/libcamera-devel/2025-January/047954.html\n> \n> Fixes: 559128b1f1b3cf (\"Thread: Add name parameter\")\n> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n\nI didn't see any other potential race condition related to the usage of\nthread_, so\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> ---\n>  src/libcamera/base/thread.cpp | 3 +--\n>  1 file changed, 1 insertion(+), 2 deletions(-)\n> \n> diff --git a/src/libcamera/base/thread.cpp b/src/libcamera/base/thread.cpp\n> index 39209ec8ad..b94a3d7490 100644\n> --- a/src/libcamera/base/thread.cpp\n> +++ b/src/libcamera/base/thread.cpp\n> @@ -292,8 +292,7 @@ void Thread::startThread()\n>  \tcurrentThreadData = data_.get();\n>  \n>  \tif (!name_.empty())\n> -\t\tpthread_setname_np(thread_.native_handle(),\n> -\t\t\t\t   name_.substr(0, 15).c_str());\n> +\t\tpthread_setname_np(pthread_self(), name_.substr(0, 15).c_str());\n>  \n>  \trun();\n>  }","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 877F1C3263\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 11 Nov 2025 11:26:34 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id AA84A60A80;\n\tTue, 11 Nov 2025 12:26:33 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4E2A3606A0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 11 Nov 2025 12:26:32 +0100 (CET)","from pendragon.ideasonboard.com (82-203-161-95.bb.dnainternet.fi\n\t[82.203.161.95])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 7233950A;\n\tTue, 11 Nov 2025 12:24:33 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"kKVSPMHs\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1762860273;\n\tbh=S4jrWf8v0CnhlfKiw7EexSD9KOnzW38LHGO+elU9IY8=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=kKVSPMHsgSrQZOOBAfpphz7lTrwPUxoxeaOx+q1EFHleZ2Be6GLcgDVHnRyIeoPjg\n\tg2wkdD6BEXhxc9tTioA9DwWKfkeJVBHNjcEqKhr6s9i5FwKqI+s1DsJd4tBfE2XCBr\n\tCUVrpBw3uOyoiQ+fdveuL762kFjI6rrNfOxTIkIE=","Date":"Tue, 11 Nov 2025 13:26:26 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH v1] libcamera: base: thread: Use `pthread_self()` when\n\tsetting name","Message-ID":"<20251111112626.GA16414@pendragon.ideasonboard.com>","References":"<20251111084133.2292217-1-barnabas.pocze@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20251111084133.2292217-1-barnabas.pocze@ideasonboard.com>","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]