How to create client in child thread
Pekka Paalanen
ppaalanen at gmail.com
Wed Jun 15 07:24:01 UTC 2016
On Wed, 15 Jun 2016 12:34:06 +0800 (CST)
袁嘉伟 <yuanjw1025 at 163.com> wrote:
> Hi, All: I try to create the client and draw it in child
> thread failed. If calling functions from child thread, it will block.
> So I want to know whether wayland(v1.9) supports to create and redraw
> the client in child thread. Perhaps anyone could tell me how to
> create a client in child thread.It's better to give me some sample
> code. Thanks.
Hi,
first of all, I would recommend not doing that. Figure out if you
really cannot achieve what you want as a separate process instead of a
thread in the compositor process.
There is no specific support for making a client in a thread. You have
to write the client part as if it was a separate process anyway. This
means you have to have an event loop in the client thread, that polls
for the Wayland connection fd and anything else it might need to
respond to.
Using a simple mutex locking scheme to protect data when accessed from
a different thread runs a risk of deadlocks if not done exactly right.
That includes not holding any locks across any call that may block,
which means you have to choose carefully which libwayland-client
functions you call.
Since it is possible that sending any request from the client may
(rarely) cause implicit flushing on the connection, I suspect it is not
safe to call any Wayland protocol API while holding locks shared with
the compositor.
Sharing any locks with the compositor would also be bad because the
client could accidentally stall the whole compositor, but that is a
caveat you have to decide for yourself.
Thanks,
pq
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 811 bytes
Desc: OpenPGP digital signature
URL: <https://lists.freedesktop.org/archives/wayland-devel/attachments/20160615/782f357d/attachment.sig>
More information about the wayland-devel
mailing list