[Spice-devel] [spice-gtk 2/3] usbredir: Use atomic for UsbDeviceManager::event_thread_run

Christophe Fergeau cfergeau at redhat.com
Thu Jun 30 07:13:25 UTC 2016


On Wed, Jun 29, 2016 at 07:20:16PM +0200, Hans de Goede wrote:
> Hi,
> 
> On 29-06-16 17:42, Christophe Fergeau wrote:
> > This variable is accessed from 2 different threads (main thread and USB
> > event thread), so some care must be taken to read/write it.
> 
> The event-thread only reads it, so I believe there is no need for this.

https://en.wikipedia.org/wiki/Memory_ordering#Runtime_memory_ordering
says that on most architectures stores can be reordered after loads, I'd
read this as: main thread sets event_thread_run to FALSE, calls
libusb_hotplug_deregister_callback(), usb event thread returns from
libusb_handle_events(), reads event_thread_run, but reads the old value
(TRUE) rather than the FALSE causing it to exit. I agree that it's
likely that either libusb_hotplug_deregister_callback() and/or
libusb_handle_events() are going to trigger some barrier, but it feels
safer to me to handle the concurrency ourselves.

Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20160630/836250fc/attachment.sig>


More information about the Spice-devel mailing list