[{"id":28552,"web_url":"https://patchwork.libcamera.org/comment/28552/","msgid":"<87sf2p6tco.fsf@redhat.com>","date":"2024-01-22T19:49:59","subject":"Re: [PATCH 05/12] test: event-thread: Destroy Object from correct\n\tthread context","submitter":{"id":177,"url":"https://patchwork.libcamera.org/api/people/177/","name":"Milan Zamazal","email":"mzamazal@redhat.com"},"content":"Laurent Pinchart <laurent.pinchart@ideasonboard.com> writes:\n\n> The EventHandler used in the test is destroyed from the main thread,\n> which is invalid for a thread-bound object bound to a different thread.\n> Fix it by destroying it with deleteLater().\n>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Milan Zamazal <mzamazal@redhat.com>\n\n> ---\n>  test/event-thread.cpp | 37 +++++++++++++++++++++++++++----------\n>  1 file changed, 27 insertions(+), 10 deletions(-)\n>\n> diff --git a/test/event-thread.cpp b/test/event-thread.cpp\n> index 88a8c07ef9f0..d6e5d27af185 100644\n> --- a/test/event-thread.cpp\n> +++ b/test/event-thread.cpp\n> @@ -85,10 +85,17 @@ private:\n>  class EventThreadTest : public Test\n>  {\n>  protected:\n> +\tint init()\n> +\t{\n> +\t\tthread_.start();\n> +\n> +\t\thandler_ = new EventHandler();\n> +\n> +\t\treturn TestPass;\n> +\t}\n> +\n>  \tint run()\n>  \t{\n> -\t\tThread thread;\n> -\t\tthread.start();\n>  \n>  \t\t/*\n>  \t\t * Fire the event notifier and then move the notifier to a\n> @@ -98,23 +105,33 @@ protected:\n>  \t\t * different thread will correctly process already pending\n>  \t\t * events in the new thread.\n>  \t\t */\n> -\t\tEventHandler handler;\n> -\t\thandler.notify();\n> -\t\thandler.moveToThread(&thread);\n> +\t\thandler_->notify();\n> +\t\thandler_->moveToThread(&thread_);\n>  \n>  \t\tthis_thread::sleep_for(chrono::milliseconds(100));\n>  \n> -\t\t/* Must stop thread before destroying the handler. */\n> -\t\tthread.exit(0);\n> -\t\tthread.wait();\n> -\n> -\t\tif (!handler.notified()) {\n> +\t\tif (!handler_->notified()) {\n>  \t\t\tcout << \"Thread event handling test failed\" << endl;\n>  \t\t\treturn TestFail;\n>  \t\t}\n>  \n>  \t\treturn TestPass;\n>  \t}\n> +\n> +\tvoid cleanup()\n> +\t{\n> +\t\t/*\n> +\t\t * Object class instances must be destroyed from the thread\n> +\t\t * they live in.\n> +\t\t */\n> +\t\thandler_->deleteLater();\n> +\t\tthread_.exit(0);\n> +\t\tthread_.wait();\n> +\t}\n> +\n> +private:\n> +\tEventHandler *handler_;\n> +\tThread thread_;\n>  };\n>  \n>  TEST_REGISTER(EventThreadTest)","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 E92BCC323E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 22 Jan 2024 19:50:07 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E09F562944;\n\tMon, 22 Jan 2024 20:50:06 +0100 (CET)","from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.133.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 97C49628B7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 22 Jan 2024 20:50:05 +0100 (CET)","from mail-ed1-f69.google.com (mail-ed1-f69.google.com\n\t[209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS\n\t(version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n\tus-mta-640-b3vwVYP8NvWWzGe0nyl3-A-1; Mon, 22 Jan 2024 14:50:03 -0500","by mail-ed1-f69.google.com with SMTP id\n\t4fb4d7f45d1cf-559421bc1c5so3224569a12.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 22 Jan 2024 11:50:03 -0800 (PST)","from nuthatch (ip-77-48-47-2.net.vodafone.cz. [77.48.47.2])\n\tby smtp.gmail.com with ESMTPSA id\n\tp6-20020a05640210c600b0055c500158b4sm1078488edu.23.2024.01.22.11.49.59\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 22 Jan 2024 11:49:59 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"gWjLF9CA\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1705953004;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\tin-reply-to:in-reply-to:references:references;\n\tbh=tdnRXe2vR82BlbJbxwnNLagGyQm9kLoSr97+OAxclaE=;\n\tb=gWjLF9CAuoc2TpntwbPdrzLJ8oX21BKwSqwHXXRWZhwUgQdQmuaib8szphPxsKxxJNDbLS\n\t/Vv9SEynSeUXlnhNewiPayfum4lHeGuDoU+21OX5faMYcO5CSUAXsbqTKh0tvbjooc91pQ\n\totk7Zg89PG1RDetSi7TT1jeeli+ZS50=","X-MC-Unique":"b3vwVYP8NvWWzGe0nyl3-A-1","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1705953000; x=1706557800;\n\th=mime-version:user-agent:message-id:date:references:in-reply-to\n\t:subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=tdnRXe2vR82BlbJbxwnNLagGyQm9kLoSr97+OAxclaE=;\n\tb=KFk9o6p/KDm28wqRXhJ8JbusWS7hgw0GyMgsFqAaj6mnY+bYrxPinTgrDrJZ85DmTG\n\t1AY+0fUwDTifULeHRAg+fL8rWnix25cqGJkzGedSohrG+pea3GSPqwEYTu3UaSfHGqVU\n\t/EETTIOxF0sXMSM9Tg53JRUSD1B6xq5ty1GXwZKbN1hj2e83aNzZsg0QvZRtZ2zr4hZ5\n\tI4mqGfyglEii2evAUHZW3pRHarIWI9txFjZWp80L/Emi1OxPSxLqXrHH2+kbPWFabEnM\n\t6n2OV71QAWb5i/1tAT+IBH3P/MO+1jk2zARCNggTxdGs+bB0DczujkN1NKhE6UPWFkqw\n\tjGGw==","X-Gm-Message-State":"AOJu0YylImFaGDwejgs6g2pQaY3a6qE+VXoYCntOkoT1cQi07rjUf3mm\n\tJpW6VkDGYNoHchcZGIOBl2jdaMqdD8t7+/gDalvmzx2BbQMkuryiybrcMOdOw+7O8+pkOlVCzMB\n\t8qKvwxAw8s8V2FPQ6S28lBBdaB3VqnZElU2HvbPtYD9TyrSd+ewXPupXukony5D0Qx/RzhrlO6K\n\t3BTp31hmCLRpjTjkCrTWEULn7TdQgPeJH5YSXNun7G0FGESBWPiuWUiRk=","X-Received":["by 2002:a50:cd02:0:b0:55c:2492:7294 with SMTP id\n\tz2-20020a50cd02000000b0055c24927294mr156498edi.59.1705953000660; \n\tMon, 22 Jan 2024 11:50:00 -0800 (PST)","by 2002:a50:cd02:0:b0:55c:2492:7294 with SMTP id\n\tz2-20020a50cd02000000b0055c24927294mr156494edi.59.1705953000311; \n\tMon, 22 Jan 2024 11:50:00 -0800 (PST)"],"X-Google-Smtp-Source":"AGHT+IGlB26bbh8qf723W45l4DJdXjTfTmSIeM1/RUnx4hDRur28p9JXN5WDr3MTwFbgP68UU9gTJg==","From":"Milan Zamazal <mzamazal@redhat.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Subject":"Re: [PATCH 05/12] test: event-thread: Destroy Object from correct\n\tthread context","In-Reply-To":"<20240121035948.4226-6-laurent.pinchart@ideasonboard.com>\n\t(Laurent Pinchart's message of \"Sun, 21 Jan 2024 05:59:41 +0200\")","References":"<20240121035948.4226-1-laurent.pinchart@ideasonboard.com>\n\t<20240121035948.4226-6-laurent.pinchart@ideasonboard.com>","Date":"Mon, 22 Jan 2024 20:49:59 +0100","Message-ID":"<87sf2p6tco.fsf@redhat.com>","User-Agent":"Gnus/5.13 (Gnus v5.13)","MIME-Version":"1.0","X-Mimecast-Spam-Score":"0","X-Mimecast-Originator":"redhat.com","Content-Type":"text/plain","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>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]