Bug 91766

Summary: There is no way to cancel wl_display_dispatch(_pending) call without a server roundtrip
Product: Wayland Reporter: Jonas Ådahl <jadahl>
Component: waylandAssignee: Wayland bug list <wayland-bugs>
Status: RESOLVED MOVED QA Contact:
Severity: normal    
Priority: medium CC: daniel
Version: unspecified   
Hardware: Other   
OS: All   
Whiteboard:
i915 platform: i915 features:
Bug Depends on:    
Bug Blocks: 91769    

Description Jonas Ådahl 2015-08-27 02:31:47 UTC
Assuming a client is using a multi threaded UI architecture, dispatching on more than one thread, either using the example API usage (wl_display_prepare_read(), poll(fds, 1, -1), ...) or the API helpers wl_display_dispatch() and wl_display_dispatch_queue(), there is currently now good way to make the dispatch call return so that the client can disconnect.

Calling wl_display_disconnect() simply closes the fd and frees the wl_display structure, causing the poll() call to stall and likely a segmentation fault if it leaves it.

Calling pthread_kill() does not work as is, since wl_display_dispatch_queue() will simply re-poll on EINTR.

What one can do is to set a variable causing the dispatcher thread not to continue dispatching and then call wl_display_sync(). This would make the server write data to the fd, causing the dispatcher thread to dispatch and return. This should IMHO only be considered a temporary work-around.

Potentially better solutions could be:

1) Make sure wl_display_disconnect() waits for all registered readers to finish, while making the readers using the helpers cancel using some fd signaling technique like eventfd. A problem with this is that the wl_display_dispatch(_queue) functions would need to return an error (maybe ECANCELED is a reasonable one) This has the side effect that existing clients doing poll(1, -1) and calling wl_display_disconnect() would suddenly start to dead lock. The dead lock could be avoided however by only waiting for wl_display_dispatch_pending() callers, meaning letting the other ones simply continue to deadlock and/or crash in their dispatcher thread as they would before.

2) Introduce new API for canceling wl_display_dispatch(_queue), letting wl_display_disconnect() stay thread unsafe, using some method similar to above. Similar issues as above, but without changing the behavior of wl_display_disconnect().
Comment 1 GitLab Migration User 2018-06-08 23:49:21 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/wayland/wayland/issues/28.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.