[{"id":3159,"web_url":"https://patchwork.libcamera.org/comment/3159/","msgid":"<20191127151452.GJ12879@bigcity.dyn.berto.se>","date":"2019-11-27T15:14:52","subject":"Re: [libcamera-devel] [PATCH 5/5] test: object-invoke: Delete\n\tInvokeObject after thread termination","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Laurent,\n\nThanks for your patch.\n\nOn 2019-11-27 10:49:09 +0200, Laurent Pinchart wrote:\n> The InvokeObject instance is created on the stack in the run() method,\n> and is thus destroyed before the thread the object is bound to\n> terminates. This creates a race condition as the object message handler\n> could be running when the object is deleted. Fix this by moving the\n> InvokeObject to a member field.\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\n> ---\n>  test/object-invoke.cpp | 24 ++++++++++++------------\n>  1 file changed, 12 insertions(+), 12 deletions(-)\n> \n> diff --git a/test/object-invoke.cpp b/test/object-invoke.cpp\n> index 6582fa75ae11..560adee14e3a 100644\n> --- a/test/object-invoke.cpp\n> +++ b/test/object-invoke.cpp\n> @@ -60,23 +60,22 @@ protected:\n>  \tint run()\n>  \t{\n>  \t\tEventDispatcher *dispatcher = Thread::current()->eventDispatcher();\n> -\t\tInvokedObject object;\n>  \n>  \t\t/*\n>  \t\t * Test that queued method invocation in the same thread goes\n>  \t\t * through the event dispatcher.\n>  \t\t */\n> -\t\tobject.invokeMethod(&InvokedObject::method,\n> -\t\t\t\t    ConnectionTypeQueued, 42);\n> +\t\tobject_.invokeMethod(&InvokedObject::method,\n> +\t\t\t\t     ConnectionTypeQueued, 42);\n>  \n> -\t\tif (object.status() != InvokedObject::NoCall) {\n> +\t\tif (object_.status() != InvokedObject::NoCall) {\n>  \t\t\tcerr << \"Method not invoked asynchronously\" << endl;\n>  \t\t\treturn TestFail;\n>  \t\t}\n>  \n>  \t\tdispatcher->processEvents();\n>  \n> -\t\tswitch (object.status()) {\n> +\t\tswitch (object_.status()) {\n>  \t\tcase InvokedObject::NoCall:\n>  \t\t\tcout << \"Method not invoked for main thread\" << endl;\n>  \t\t\treturn TestFail;\n> @@ -87,7 +86,7 @@ protected:\n>  \t\t\tbreak;\n>  \t\t}\n>  \n> -\t\tif (object.value() != 42) {\n> +\t\tif (object_.value() != 42) {\n>  \t\t\tcout << \"Method invoked with incorrect value for main thread\" << endl;\n>  \t\t\treturn TestFail;\n>  \t\t}\n> @@ -96,15 +95,15 @@ protected:\n>  \t\t * Move the object to a thread and verify that auto method\n>  \t\t * invocation is delivered in the correct thread.\n>  \t\t */\n> -\t\tobject.reset();\n> -\t\tobject.moveToThread(&thread_);\n> +\t\tobject_.reset();\n> +\t\tobject_.moveToThread(&thread_);\n>  \n>  \t\tthread_.start();\n>  \n> -\t\tobject.invokeMethod(&InvokedObject::method,\n> -\t\t\t\t    ConnectionTypeBlocking, 42);\n> +\t\tobject_.invokeMethod(&InvokedObject::method,\n> +\t\t\t\t     ConnectionTypeBlocking, 42);\n>  \n> -\t\tswitch (object.status()) {\n> +\t\tswitch (object_.status()) {\n>  \t\tcase InvokedObject::NoCall:\n>  \t\t\tcout << \"Method not invoked for custom thread\" << endl;\n>  \t\t\treturn TestFail;\n> @@ -115,7 +114,7 @@ protected:\n>  \t\t\tbreak;\n>  \t\t}\n>  \n> -\t\tif (object.value() != 42) {\n> +\t\tif (object_.value() != 42) {\n>  \t\t\tcout << \"Method invoked with incorrect value for custom thread\" << endl;\n>  \t\t\treturn TestFail;\n>  \t\t}\n> @@ -131,6 +130,7 @@ protected:\n>  \n>  private:\n>  \tThread thread_;\n> +\tInvokedObject object_;\n>  };\n>  \n>  TEST_REGISTER(ObjectInvokeTest)\n> -- \n> Regards,\n> \n> Laurent Pinchart\n> \n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from mail-lj1-x241.google.com (mail-lj1-x241.google.com\n\t[IPv6:2a00:1450:4864:20::241])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E6BE160C33\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 27 Nov 2019 16:14:53 +0100 (CET)","by mail-lj1-x241.google.com with SMTP id k8so14346708ljh.5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 27 Nov 2019 07:14:53 -0800 (PST)","from localhost (h-93-159.A463.priv.bahnhof.se. [46.59.93.159])\n\tby smtp.gmail.com with ESMTPSA id\n\tx23sm7171362lfe.8.2019.11.27.07.14.52\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 27 Nov 2019 07:14:52 -0800 (PST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ragnatech-se.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:content-transfer-encoding:in-reply-to\n\t:user-agent; bh=Jpsm49Q7dM/W7vwNzk9j69AzmEjBYh2R06/orhM5dk4=;\n\tb=g8gJsFP3VclY5E1Fl1iheM+WP6aQe4J5LKFI/zADym6mKpcjfYvmTAI/IDiNm6ihWh\n\tK+KKlMDEpcvSvY74rlt+zV6CPcNOHoB3kCV3B/81nffOKKH13ESIf2WgQKC0sg/KOyF2\n\t8UsES7oU+xy1kQSh3A5bpX7M6AKO/1y2wyAVMSBIbY62bA/gJuXbM8gLn62Bv2P4lMcT\n\tRYypjzpM5ZRSuO2fjLf7Dis3HId17OF6Q+jlm/bqlqtbQJukT1FWEp9zb9FqRCP8nNh7\n\tHarrqp0iQFSc7SUGZgtyftghZegGH1GIBGDp9U48XI5svT2yoI5hUNE8Mo5tRUzChbdL\n\t05JQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:content-transfer-encoding\n\t:in-reply-to:user-agent;\n\tbh=Jpsm49Q7dM/W7vwNzk9j69AzmEjBYh2R06/orhM5dk4=;\n\tb=YqhzdSf6RyGMPdLHjUK6/B7sNZQsZ1f6mfYCRwykTP57FabzyeQCbEGtnZWTwMTLJb\n\tO7MU97usM2ZcQ3mUg7n1JkDL6JJi2XCFjuEvs7Al3Wc3PbcI5znxQ9InDTrWWNgpwgkU\n\tdxz4AZRqXxHGkxmdklMktGnB4wG/sBn7dHcV6OPzAWG5pB7nNHecX2IOBVryKM1Al1Ew\n\tsL4yPlws0XtM+cX/QLLiUENAl//8Lie68QP+6jIHW+bRKgRLlNZ7nUbAeMKd4qOwHuKW\n\tVw9ULZd6j0CeejdbYU2Ste+aFdbV22fWC8fXpbCWRjOS1zHT56A3JrKbUzRrFsGC1Vnq\n\tONnQ==","X-Gm-Message-State":"APjAAAWiirQ9BU6kDG/laxDvsOv5wJE+5ueuAWxOlPSgI2TpbBI2YnGL\n\tU/uIoYCGEKz9N2uk9PhIt3sHTMX0xeD9Jw==","X-Google-Smtp-Source":"APXvYqwjnCK8a54n/3yczFwz4Vknjx+secGqiQxYCkrXFCK2LfhD/dPNwck0j7sommNmMY0XZNCXpg==","X-Received":"by 2002:a2e:b4f6:: with SMTP id\n\ts22mr18725658ljm.218.1574867693306; \n\tWed, 27 Nov 2019 07:14:53 -0800 (PST)","Date":"Wed, 27 Nov 2019 16:14:52 +0100","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20191127151452.GJ12879@bigcity.dyn.berto.se>","References":"<20191127084909.10612-1-laurent.pinchart@ideasonboard.com>\n\t<20191127084909.10612-5-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20191127084909.10612-5-laurent.pinchart@ideasonboard.com>","User-Agent":"Mutt/1.12.1 (2019-06-15)","Subject":"Re: [libcamera-devel] [PATCH 5/5] test: object-invoke: Delete\n\tInvokeObject after thread termination","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>","X-List-Received-Date":"Wed, 27 Nov 2019 15:14:54 -0000"}}]