public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Simon Ser <simon.ser@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: martin.peres@intel.com
Subject: [igt-dev] [PATCH i-g-t] lib/igt_chamelium: wait for worker thread to finish
Date: Wed,  5 Jun 2019 13:36:27 +0300	[thread overview]
Message-ID: <20190605103627.32526-1-simon.ser@intel.com> (raw)

Whenever we change a pipe's resolution, we need to perform a FSM on the
Chamelium: the video receiver will be restarted and the Chamelium device will
send a hotplug event. All of this happens during the XML-RPC call.

To handle the hotplug event, we start a new thread (and execute the XML-RPC
request in the main thread in a blocking fashion). Some state is associated
with the hotplug thread and stored in fsm_monitor_args. We initialize this
state before starting the thread, and perform cleanup after cancelling it.

However pthread_cancel is asynchronous: it merely queues a cancellation request
for the thread. Thus cleaning up after pthread_cancel is racy: the thread might
still be running and using fsm_monitor_args.mon. Since this is shared memory,
this can lead to segmentation faults or strange behaviour.

This commit fixes the race by calling pthread_join before cleaning up the
state. This ensures that either the thread has been successfully cancelled,
either it has terminated.

This is an attempt to fix this bug:
https://bugs.freedesktop.org/show_bug.cgi?id=110730

Signed-off-by: Simon Ser <simon.ser@intel.com>
---
 lib/igt_chamelium.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lib/igt_chamelium.c b/lib/igt_chamelium.c
index 75f03d8469aa..eaf3b5b07097 100644
--- a/lib/igt_chamelium.c
+++ b/lib/igt_chamelium.c
@@ -302,6 +302,7 @@ static xmlrpc_value *__chamelium_rpc_va(struct chamelium *chamelium,

 	if (fsm_port) {
 		pthread_cancel(fsm_thread_id);
+		pthread_join(fsm_thread_id, NULL);
 		igt_cleanup_hotplug(monitor_args.mon);
 	}

--
2.21.0

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

             reply	other threads:[~2019-06-05 10:36 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-05 10:36 Simon Ser [this message]
2019-06-05 11:51 ` [igt-dev] ✗ Fi.CI.BAT: failure for lib/igt_chamelium: wait for worker thread to finish Patchwork
2019-06-05 12:03   ` Ser, Simon
2019-06-05 15:47 ` [igt-dev] [PATCH i-g-t] " Arkadiusz Hiler
2019-06-05 16:44 ` [igt-dev] ✗ Fi.CI.BAT: failure for lib/igt_chamelium: wait for worker thread to finish (rev2) Patchwork
2019-06-06  7:05   ` Ser, Simon
2019-06-06 13:50 ` [igt-dev] ✓ Fi.CI.BAT: success for lib/igt_chamelium: wait for worker thread to finish (rev3) Patchwork
2019-06-06 15:30 ` [igt-dev] ✓ Fi.CI.BAT: success for lib/igt_chamelium: wait for worker thread to finish (rev4) Patchwork
2019-06-08 16:21 ` [igt-dev] ✗ Fi.CI.IGT: failure for lib/igt_chamelium: wait for worker thread to finish (rev3) Patchwork
2019-06-08 22:38 ` [igt-dev] ✓ Fi.CI.IGT: success for lib/igt_chamelium: wait for worker thread to finish (rev4) Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190605103627.32526-1-simon.ser@intel.com \
    --to=simon.ser@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=martin.peres@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox