[igt-dev] [PATCH i-g-t] lib/igt_chamelium: wait for worker thread to finish

Arkadiusz Hiler arkadiusz.hiler at intel.com
Wed Jun 5 15:47:23 UTC 2019


On Wed, Jun 05, 2019 at 01:36:27PM +0300, Simon Ser wrote:
> 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 at intel.com>
Reviewed-by: Arkadiusz Hiler <arkadiusz.hiler at intel.com>


More information about the igt-dev mailing list