{"id":19451,"url":"https://patchwork.libcamera.org/api/patches/19451/?format=json","web_url":"https://patchwork.libcamera.org/patch/19451/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20240123011249.22716-4-laurent.pinchart@ideasonboard.com>","date":"2024-01-23T01:12:40","name":"[v2,03/12] test: object-delete: Test deferred delete just before thread stops","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"7a0892cfab30bde7f85533907f2bbc8c3bef223f","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/19451/mbox/","series":[{"id":4157,"url":"https://patchwork.libcamera.org/api/series/4157/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4157","date":"2024-01-23T01:12:37","name":"libcamera: Hardening against thread race conditions","version":2,"mbox":"https://patchwork.libcamera.org/series/4157/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/19451/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/19451/checks/","tags":{},"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 B4C0EC32BD\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 23 Jan 2024 01:12:53 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0020862950;\n\tTue, 23 Jan 2024 02:12:52 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3DA7B628B7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 23 Jan 2024 02:12:50 +0100 (CET)","from pendragon.ideasonboard.com (89-27-53-110.bb.dnainternet.fi\n\t[89.27.53.110])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id D1F54188E;\n\tTue, 23 Jan 2024 02:11:36 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"kYEnCJGr\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1705972297;\n\tbh=kTtTbmkIWNTNAxqLFky+NCKArqRqxUteFktiBMHbrW4=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=kYEnCJGreGmfXSQb798z5QSNgT/buKIkmqBfL/IZhb+6Uqlv0lUjI6s0B4yrmD6Pb\n\tWOANG37pnpfqrDaDYrYE3jvOY5o1BDmzFPScfN0ctFjjcgxINAHTD8zQF7BywvRCMR\n\t4C+i0KvF62DtdRE1ZCuV505zfdx97fAngd7VPty4=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Subject":"[PATCH v2 03/12] test: object-delete: Test deferred delete just\n\tbefore thread stops","Date":"Tue, 23 Jan 2024 03:12:40 +0200","Message-ID":"<20240123011249.22716-4-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.43.0","In-Reply-To":"<20240123011249.22716-1-laurent.pinchart@ideasonboard.com>","References":"<20240123011249.22716-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","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>"},"content":"The Object::deleteLater() function is expected to not race with stopping\nthe thread the object is bound to. Add a test for this.\n\nThe test currently fails, demonstrating a bug in libcamera.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\nChanges since v1:\n\n- Fix typo in commit message\n---\n test/object-delete.cpp | 30 +++++++++++++++++++++++++-----\n 1 file changed, 25 insertions(+), 5 deletions(-)","diff":"diff --git a/test/object-delete.cpp b/test/object-delete.cpp\nindex eabefe935974..80b7dc41cd37 100644\n--- a/test/object-delete.cpp\n+++ b/test/object-delete.cpp\n@@ -33,10 +33,10 @@ public:\n \tunsigned int *deleteCount_;\n };\n \n-class NewThread : public Thread\n+class DeleterThread : public Thread\n {\n public:\n-\tNewThread(Object *obj)\n+\tDeleterThread(Object *obj)\n \t\t: object_(obj)\n \t{\n \t}\n@@ -63,9 +63,9 @@ protected:\n \t\tunsigned int count = 0;\n \t\tTestObject *obj = new TestObject(&count);\n \n-\t\tNewThread thread(obj);\n-\t\tthread.start();\n-\t\tthread.wait();\n+\t\tDeleterThread delThread(obj);\n+\t\tdelThread.start();\n+\t\tdelThread.wait();\n \n \t\tThread::current()->dispatchMessages(Message::Type::DeferredDelete);\n \n@@ -89,6 +89,26 @@ protected:\n \t\t\treturn TestFail;\n \t\t}\n \n+\t\t/*\n+\t\t * Test that deleteLater() works properly when called just\n+\t\t * before the object's thread exits.\n+\t\t */\n+\t\tThread boundThread;\n+\t\tboundThread.start();\n+\n+\t\tcount = 0;\n+\t\tobj = new TestObject(&count);\n+\t\tobj->moveToThread(&boundThread);\n+\n+\t\tobj->deleteLater();\n+\t\tboundThread.exit();\n+\t\tboundThread.wait();\n+\n+\t\tif (count != 1) {\n+\t\t\tcout << \"Object deletion right before thread exit failed (\" << count << \")\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n \t\treturn TestPass;\n \t}\n };\n","prefixes":["v2","03/12"]}